15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.List;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 import com.google.common.base.Objects;
25 import com.google.common.base.Preconditions;
26 import com.google.common.collect.Lists;
33 private final static Logger
LOG = LoggerFactory.getLogger(AnalyticInfo.class);
47 super(
new ArrayList<Expr>(),
new ArrayList<FunctionCallExpr>());
50 for (
Expr analyticExpr: analyticExprs) {
51 aggregateExprs_.add(((
AnalyticExpr) analyticExpr).getFnCall());
65 ArrayList<Expr> analyticExprs,
Analyzer analyzer) {
66 Preconditions.checkState(analyticExprs != null && !analyticExprs.isEmpty());
67 Expr.removeDuplicates(analyticExprs);
69 result.createTupleDescs(analyzer);
73 result.outputTupleDesc_.setIsMaterialized(
false);
74 result.intermediateTupleDesc_.setIsMaterialized(
false);
77 Preconditions.checkState(analyticExprs.size() ==
78 result.outputTupleDesc_.getSlots().size());
79 for (
int i = 0; i < analyticExprs.size(); ++i) {
80 result.analyticTupleSmap_.put(result.analyticExprs_.get(i),
81 new SlotRef(result.outputTupleDesc_.getSlots().get(i)));
82 result.outputTupleDesc_.getSlots().
get(i).setSourceExpr(
83 result.analyticExprs_.get(i));
85 LOG.trace(
"analytictuple=" + result.outputTupleDesc_.debugString());
86 LOG.trace(
"analytictuplesmap=" + result.analyticTupleSmap_.debugString());
87 LOG.trace(
"analytic info:\n" + result.debugString());
97 Preconditions.checkState(analyticExpr.isAnalyzed_);
98 List<Expr> partitionExprs = ((
AnalyticExpr) analyticExpr).getPartitionExprs();
99 if (partitionExprs == null)
continue;
101 commonPartitionExprs_.addAll(partitionExprs);
103 commonPartitionExprs_.retainAll(partitionExprs);
118 ids.add(slotDesc.getId());
124 materializedSlots_.clear();
125 List<Expr> exprs = Lists.newArrayList();
126 for (
int i = 0; i < analyticExprs_.size(); ++i) {
127 SlotDescriptor outputSlotDesc = outputTupleDesc_.getSlots().
get(i);
129 intermediateTupleDesc_.getSlots().
get(i).setIsMaterialized(
true);
130 exprs.add(analyticExprs_.get(i));
131 materializedSlots_.add(i);
133 List<Expr> resolvedExprs = Expr.substituteList(exprs, smap, analyzer,
false);
134 analyzer.materializeSlots(resolvedExprs);
144 ArrayList<SlotDescriptor> slots = intermediateTupleDesc_.getSlots();
147 int numMaterializedSlots = 0;
149 if (slotDesc.isMaterialized()) ++numMaterializedSlots;
151 Preconditions.checkState(numMaterializedSlots ==
152 materializedSlots_.size());
156 for (
int i = 0; i < analyticExprs_.size(); ++i) {
157 Expr analyticExpr = analyticExprs_.get(i);
158 Type slotType = slots.get(slotIdx).getType();
159 Preconditions.checkState(analyticExpr.getType().equals(slotType),
160 String.format(
"Analytic expr %s returns type %s but its analytic tuple " +
161 "slot has type %s", analyticExpr.toSql(),
162 analyticExpr.
getType().toString(), slotType.toString()));
169 StringBuilder out =
new StringBuilder(super.debugString());
170 out.append(Objects.toStringHelper(
this)
174 return out.toString();
TupleDescriptor intermediateTupleDesc_
ArrayList< Expr > getAnalyticExprs()
final ExprSubstitutionMap analyticTupleSmap_
static AnalyticInfo create(ArrayList< Expr > analyticExprs, Analyzer analyzer)
ExprSubstitutionMap getSmap()
List< Expr > getCommonPartitionExprs()
final List< Expr > commonPartitionExprs_
ArrayList< SlotDescriptor > getSlots()
void getRefdSlots(List< SlotId > ids)
void computeCommonPartitionExprs()
void materializeRequiredSlots(Analyzer analyzer, ExprSubstitutionMap smap)
AnalyticInfo(ArrayList< Expr > analyticExprs)
final ArrayList< Expr > analyticExprs_