1 package com.cloudera.impala.analysis;
3 import java.util.ArrayList;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
12 import com.google.common.base.Objects;
13 import com.google.common.base.Preconditions;
14 import com.google.common.collect.Lists;
21 private final static Logger
LOG =
22 LoggerFactory.getLogger(AggregateInfoBase.class);
56 ArrayList<FunctionCallExpr> aggExprs) {
57 Preconditions.checkState(groupingExprs != null || aggExprs != null);
59 groupingExprs != null ? Expr.cloneList(groupingExprs) :
new ArrayList<Expr>();
60 Preconditions.checkState(aggExprs != null || !(
this instanceof
AnalyticInfo));
62 aggExprs != null ? Expr.cloneList(aggExprs) :
new ArrayList<FunctionCallExpr>();
89 analyzer.getDescTbl().createTupleDescriptor(
91 List<Expr> exprs = Lists.newArrayListWithCapacity(
96 int aggregateExprStartIndex = groupingExprs_.size();
97 for (
int i = 0; i < exprs.size(); ++i) {
98 Expr expr = exprs.get(i);
100 slotDesc.setLabel(expr.toSql());
101 slotDesc.setSourceExpr(expr);
102 slotDesc.setStats(ColumnStats.fromExpr(expr));
103 Preconditions.checkState(expr.getType().isValid());
104 slotDesc.setType(expr.getType());
105 if (i < aggregateExprStartIndex) {
111 analyzer.createAuxEquivPredicate(
new SlotRef(slotDesc), expr.clone());
116 if (aggExpr.isMergeAggFn()) {
117 slotDesc.setLabel(aggExpr.getChild(0).toSql());
118 slotDesc.setSourceExpr(aggExpr.getChild(0));
120 slotDesc.setLabel(aggExpr.toSql());
121 slotDesc.setSourceExpr(aggExpr);
125 if (aggExpr.getFnName().getFunction().equals(
"count")) {
128 slotDesc.setIsNullable(
false);
130 if (!isOutputTuple) {
132 if (intermediateType != null) {
135 slotDesc.setType(intermediateType);
137 Preconditions.checkState(expr.getType().isDecimal());
143 String prefix = (isOutputTuple ?
"result " :
"intermediate ");
144 LOG.trace(prefix +
" tuple=" + result.debugString());
174 for (
Expr aggExpr: aggExprs) {
176 if (intermediateType != null)
return true;
182 StringBuilder out =
new StringBuilder();
183 out.append(Objects.toStringHelper(
this)
187 ?
"null" : intermediateTupleDesc_.debugString())
189 ?
"null" : outputTupleDesc_.debugString())
191 return out.toString();
boolean isWildcardDecimal()
TupleDescriptor getIntermediateTupleDesc()
ArrayList< Expr > groupingExprs_
TupleDescriptor intermediateTupleDesc_
static< TextendsExpr > boolean requiresIntermediateTuple(List< T > aggExprs)
abstract void materializeRequiredSlots(Analyzer analyzer, ExprSubstitutionMap smap)
ArrayList< Expr > getGroupingExprs()
abstract String tupleDebugName()
TupleDescriptor outputTupleDesc_
boolean requiresIntermediateTuple()
TupleId getOutputTupleId()
ArrayList< FunctionCallExpr > aggregateExprs_
ArrayList< FunctionCallExpr > getAggregateExprs()
void createTupleDescs(Analyzer analyzer)
TupleDescriptor createTupleDesc(Analyzer analyzer, boolean isOutputTuple)
AggregateInfoBase(ArrayList< Expr > groupingExprs, ArrayList< FunctionCallExpr > aggExprs)
TupleDescriptor getOutputTupleDesc()
TupleId getIntermediateTupleId()
ArrayList< Integer > materializedSlots_