15 package com.cloudera.impala.planner;
17 import java.util.ArrayList;
18 import java.util.List;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
30 import com.cloudera.impala.thrift.TAggregationNode;
31 import com.cloudera.impala.thrift.TExplainLevel;
32 import com.cloudera.impala.thrift.TExpr;
33 import com.cloudera.impala.thrift.TPlanNode;
34 import com.cloudera.impala.thrift.TPlanNodeType;
35 import com.cloudera.impala.thrift.TQueryOptions;
36 import com.google.common.base.Objects;
37 import com.google.common.base.Preconditions;
38 import com.google.common.collect.Lists;
39 import com.google.common.collect.Sets;
46 private final static Logger
LOG = LoggerFactory.getLogger(AggregationNode.class);
68 nullableTupleIds_.addAll(input.getNullableTupleIds());
76 super(
id, src,
"AGGREGATE");
95 Preconditions.checkState(!tupleIds_.isEmpty());
98 tupleIds_.add(aggInfo_.getIntermediateTupleId());
110 if (
tupleIds_.get(0).equals(aggInfo_.getResultTupleId()) && !aggInfo_.isMerge()) {
113 Set<SlotId> groupBySlots = Sets.newHashSet();
114 for (
int i = 0; i < aggInfo_.getGroupingExprs().size(); ++i) {
115 groupBySlots.add(aggInfo_.getOutputTupleDesc().getSlots().get(i).
getId());
117 ArrayList<Expr> bindingPredicates =
118 analyzer.getBoundPredicates(tupleIds_.get(0), groupBySlots,
true);
119 conjuncts_.addAll(bindingPredicates);
124 analyzer.createEquivConjuncts(tupleIds_.get(0),
conjuncts_, groupBySlots);
139 aggInfo_.checkConsistency();
144 super.computeStats(analyzer);
157 cardinality_ = aggInfo_.getGroupingExprs().isEmpty() ? 1 :
158 Expr.getNumDistinctValues(aggInfo_.getGroupingExprs());
160 LOG.trace(
"Agg: cardinality=" + Long.toString(
cardinality_));
161 if (cardinality_ > 0) {
166 if (cardinality_ < 0) cardinality_ = -1;
169 if (cardinality_ == -1) {
171 cardinality_ = getChild(0).getCardinality();
174 cardinality_ = Math.min(getChild(0).getCardinality(), cardinality_);
177 LOG.trace(
"stats Agg: cardinality=" + Long.toString(
cardinality_));
182 return Objects.toStringHelper(
this)
184 .addValue(super.debugString())
190 msg.node_type = TPlanNodeType.AGGREGATION_NODE;
192 List<TExpr> aggregateFunctions = Lists.newArrayList();
195 aggregateFunctions.add(e.treeToThrift());
197 aggInfo_.checkConsistency();
198 msg.agg_node =
new TAggregationNode(
202 List<Expr> groupingExprs = aggInfo_.getGroupingExprs();
203 if (groupingExprs != null) {
204 msg.agg_node.setGrouping_exprs(Expr.treesToThrift(groupingExprs));
216 TExplainLevel detailLevel) {
217 StringBuilder output =
new StringBuilder();
220 if (nameDetail != null) output.append(
" [" + nameDetail +
"]");
223 if (detailLevel.ordinal() >= TExplainLevel.STANDARD.ordinal()) {
225 aggInfo_.getAggregateExprs().size() > 0) {
226 output.append(detailPrefix +
"output: ")
235 output.append(detailPrefix +
"group by: ")
239 output.append(detailPrefix +
"having: ")
243 return output.toString();
249 "PlanNode must be placed into a fragment before calling this method.");
251 long perHostCardinality = fragment_.getNumDistinctValues(aggInfo_.getGroupingExprs());
252 if (perHostCardinality == -1) {
259 perHostCardinality = Math.min(perHostCardinality,
cardinality_);
261 perHostMemCost_ += Math.max(perHostCardinality *
avgRowSize_ *
void init(Analyzer analyzer)
void assignConjuncts(Analyzer analyzer)
ArrayList< Expr > getGroupingExprs()
ArrayList< TupleId > tupleIds_
AggregationNode(PlanNodeId id, AggregationNode src)
ExprSubstitutionMap getCombinedChildSmap()
String getExplainString()
void computeStats(Analyzer analyzer)
static final long DEFAULT_PER_HOST_MEM
TupleId getOutputTupleId()
ArrayList< FunctionCallExpr > getAggregateExprs()
String getNodeExplainString(String prefix, String detailPrefix, TExplainLevel detailLevel)
void toThrift(TPlanNode msg)
ArrayList< FunctionCallExpr > getMaterializedAggregateExprs()
void computeCosts(TQueryOptions queryOptions)
void setIntermediateTuple()
AggregationNode(PlanNodeId id, PlanNode input, AggregateInfo aggInfo)
void computeMemLayout(Analyzer analyzer)
AggregateInfo getAggInfo()
static final double HASH_TBL_SPACE_OVERHEAD
void unsetNeedsFinalize()
final AggregateInfo aggInfo_
static final long MIN_HASH_TBL_MEM
double computeSelectivity()
String getDisplayLabelDetail()
TupleId getIntermediateTupleId()
final String getDisplayLabel()
ExprSubstitutionMap outputSmap_