Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CrossJoinNode.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.planner;
16 
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 
23 import com.cloudera.impala.thrift.TExplainLevel;
24 import com.cloudera.impala.thrift.TPlanNode;
25 import com.cloudera.impala.thrift.TPlanNodeType;
26 import com.cloudera.impala.thrift.TQueryOptions;
27 import com.google.common.base.Objects;
28 
32 public class CrossJoinNode extends PlanNode {
33  private final static Logger LOG = LoggerFactory.getLogger(CrossJoinNode.class);
34 
35  // Default per-host memory requirement used if no valid stats are available.
36  // TODO: Come up with a more useful heuristic (e.g., based on scanned partitions).
37  private final static long DEFAULT_PER_HOST_MEM = 2L * 1024L * 1024L * 1024L;
38 
39  public CrossJoinNode(PlanNode outer, PlanNode inner) {
40  super("CROSS JOIN");
41  tupleIds_.addAll(outer.getTupleIds());
42  tupleIds_.addAll(inner.getTupleIds());
43  tblRefIds_.addAll(outer.getTblRefIds());
44  tblRefIds_.addAll(inner.getTblRefIds());
45  children_.add(outer);
46  children_.add(inner);
47 
48  // Inherits all the nullable tuple from the children
49  // Mark tuples that form the "nullable" side of the outer join as nullable.
50  nullableTupleIds_.addAll(outer.getNullableTupleIds());
51  nullableTupleIds_.addAll(inner.getNullableTupleIds());
52  }
53 
54  @Override
55  public void init(Analyzer analyzer) throws InternalException {
56  super.init(analyzer);
57  assignedConjuncts_ = analyzer.getAssignedConjuncts();
58  }
59 
60  @Override
61  public void computeStats(Analyzer analyzer) {
62  super.computeStats(analyzer);
63  if (getChild(0).cardinality_ == -1 || getChild(1).cardinality_ == -1) {
64  cardinality_ = -1;
65  } else {
67  getChild(1).cardinality_);
68  if (computeSelectivity() != -1) {
69  cardinality_ = Math.round(((double) cardinality_) * computeSelectivity());
70  }
71  }
72  LOG.debug("stats CrossJoin: cardinality=" + Long.toString(cardinality_));
73  }
74 
75  @Override
76  protected String debugString() {
77  return Objects.toStringHelper(this)
78  .addValue(super.debugString())
79  .toString();
80  }
81 
82  @Override
83  protected void toThrift(TPlanNode msg) {
84  msg.node_type = TPlanNodeType.CROSS_JOIN_NODE;
85  }
86 
87  @Override
88  protected String getNodeExplainString(String prefix, String detailPrefix,
89  TExplainLevel detailLevel) {
90  StringBuilder output = new StringBuilder();
91  // Always a BROADCAST, but print it anyway so it's clear to users
92  output.append(String.format("%s%s:%s [%s]\n", prefix, id_.toString(),
94  if (detailLevel.ordinal() >= TExplainLevel.STANDARD.ordinal()) {
95  if (!conjuncts_.isEmpty()) {
96  output.append(detailPrefix + "predicates: ")
97  .append(getExplainString(conjuncts_) + "\n");
98  }
99  }
100  return output.toString();
101  }
102 
103  @Override
104  public void computeCosts(TQueryOptions queryOptions) {
105  if (getChild(1).getCardinality() == -1 || getChild(1).getAvgRowSize() == -1
106  || numNodes_ == 0) {
108  return;
109  }
110  perHostMemCost_ = (long) Math.ceil(getChild(1).cardinality_ * getChild(1).avgRowSize_);
111  }
112 }
CrossJoinNode(PlanNode outer, PlanNode inner)
static long multiplyCardinalities(long a, long b)
Definition: PlanNode.java:541
String getNodeExplainString(String prefix, String detailPrefix, TExplainLevel detailLevel)
void computeCosts(TQueryOptions queryOptions)