15 package com.cloudera.impala.planner;
17 import java.util.List;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
33 import com.cloudera.impala.thrift.TExplainLevel;
34 import com.cloudera.impala.thrift.TPartitionType;
35 import com.cloudera.impala.thrift.TPlanFragment;
36 import com.google.common.base.Preconditions;
37 import com.google.common.base.Predicates;
38 import com.google.common.collect.Lists;
64 private final static Logger
LOG = LoggerFactory.getLogger(PlanFragment.class);
107 if (node == null)
return;
108 node.setFragment(
this);
110 for (
PlanNode child : node.getChildren()) {
133 Preconditions.checkState(
sink_ == null);
136 streamSink.setFragment(
this);
144 List<ExchangeNode> exchNodes = Lists.newArrayList();
145 planRoot_.collect(Predicates.instanceOf(ExchangeNode.class), exchNodes);
148 List<List<Expr>> senderPartitionExprs = Lists.newArrayList();
150 Preconditions.checkState(!exchNode.getChildren().isEmpty());
151 PlanFragment senderFragment = exchNode.getChild(0).getFragment();
152 Preconditions.checkNotNull(senderFragment);
153 if (!senderFragment.getOutputPartition().isHashPartitioned())
continue;
154 List<Expr> partExprs = senderFragment.getOutputPartition().getPartitionExprs();
157 Preconditions.checkState(
159 senderPartitionExprs.add(partExprs);
166 senderPartitionExprs.add(dataPartition_.getPartitionExprs());
168 analyzer.castToUnionCompatibleTypes(senderPartitionExprs);
171 throw new IllegalStateException(e);
180 return dataPartition_ == DataPartition.UNPARTITIONED ? 1 : planRoot_.getNumNodes();
197 HashJoinNode hashJoinNode = (HashJoinNode)node;
199 if (!childResult)
return false;
214 List<BinaryPredicate> joinConjuncts = hashJoinNode.getEqJoinConjuncts();
218 for (
Expr c: joinConjuncts) {
219 if (c.getChild(0) instanceof
SlotRef) {
220 hashJoinNode.setAddProbeFilters(
true);
232 HdfsScanNode scanNode = (HdfsScanNode) node;
233 Preconditions.checkNotNull(scanNode.desc_);
234 Preconditions.checkNotNull(scanNode.desc_.getTable() instanceof
HdfsTable);
242 for (
PlanNode child : node.getChildren()) {
258 Preconditions.checkState(numNodes >= 0);
260 if (numNodes == 0)
return 0;
261 for (
Expr expr: exprs) {
262 long numDistinct = expr.getNumDistinctValues();
263 if (numDistinct == -1) {
268 numDistinct = (long)Math.max((
double) numDistinct / (
double) numNodes, 1L);
270 result = PlanNode.multiplyCardinalities(result, numDistinct);
276 TPlanFragment result =
new TPlanFragment();
277 result.setDisplay_name(fragmentId_.toString());
278 if (
planRoot_ != null) result.setPlan(planRoot_.treeToThrift());
280 result.setOutput_exprs(Expr.treesToThrift(
outputExprs_));
282 if (
sink_ != null) result.setOutput_sink(sink_.toThrift());
283 result.setPartition(dataPartition_.toThrift());
288 StringBuilder str =
new StringBuilder();
290 String rootPrefix =
"";
292 String detailPrefix =
"| ";
293 if (explainLevel == TExplainLevel.VERBOSE) {
296 detailPrefix = prefix +
"| ";
297 str.append(String.format(
"%s:PLAN FRAGMENT [%s]\n", fragmentId_.toString(),
300 str.append(sink_.getExplainString(prefix, detailPrefix, explainLevel) +
"\n");
305 str.append(sink_.getExplainString(prefix, detailPrefix, explainLevel));
306 if (explainLevel.ordinal() >= TExplainLevel.STANDARD.ordinal()) {
307 str.append(prefix +
"|\n");
311 str.append(planRoot_.getExplainString(rootPrefix, prefix, explainLevel));
313 return str.toString();
324 return destNode_.getFragment();
329 this.dataPartition_ = dataPartition;
333 this.outputPartition_ = outputPartition;
345 Preconditions.checkState(this.sink_ == null);
346 Preconditions.checkNotNull(sink);
347 sink.setFragment(
this);
356 Preconditions.checkState(newRoot.getChildren().size() == 1);
359 planRoot_.setFragment(
this);
String getExplainString()
List< Expr > getPartitionExprs()
DataPartition getOutputPartition()
long getNumDistinctValues(List< Expr > exprs)
static final DataPartition UNPARTITIONED
void setFragmentInPlanTree(PlanNode node)
HdfsFileFormat getMajorityFormat()
void setDestination(ExchangeNode destNode)
List< Expr > outputExprs_
void setOutputPartition(DataPartition outputPartition)
void setDataPartition(DataPartition dataPartition)
void setPlanRoot(PlanNode root)
String getExplainString(TExplainLevel explainLevel)
final TupleDescriptor desc_
PlanFragment(PlanFragmentId id, PlanNode root, DataPartition partition)
ExchangeNode getDestNode()
boolean computeCanAddSlotFilters(PlanNode node)
PlanFragment getDestFragment()
DataPartition dataPartition_
NULL_AWARE_LEFT_ANTI_JOIN
List< Expr > getOutputExprs()
DataPartition getDataPartition()
final PlanFragmentId fragmentId_
void setSink(DataSink sink)
void addPlanRoot(PlanNode newRoot)
DataPartition outputPartition_
boolean isHashPartitioned()
void finalize(Analyzer analyzer)
void setOutputExprs(List< Expr > outputExprs)
DistributionMode getDistributionMode()