15 package com.cloudera.impala.planner;
17 import java.util.List;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
30 import com.cloudera.impala.thrift.TAnalyticNode;
31 import com.cloudera.impala.thrift.TExplainLevel;
32 import com.cloudera.impala.thrift.TPlanNode;
33 import com.cloudera.impala.thrift.TPlanNodeType;
34 import com.cloudera.impala.thrift.TQueryOptions;
35 import com.google.common.base.Joiner;
36 import com.google.common.base.Objects;
37 import com.google.common.base.Preconditions;
38 import com.google.common.collect.Lists;
44 private final static Logger
LOG = LoggerFactory.getLogger(AnalyticEvalNode.class);
80 List<Expr> analyticFnCalls, List<Expr> partitionExprs,
81 List<OrderByElement> orderByElements,
AnalyticWindow analyticWindow,
86 Preconditions.checkState(!tupleIds_.contains(outputTupleDesc.getId()));
88 tupleIds_.add(outputTupleDesc.getId());
101 children_.add(input);
102 nullableTupleIds_.addAll(input.getNullableTupleIds());
113 intermediateTupleDesc_.computeMemLayout();
126 LOG.trace(
"desctbl: " + analyzer.getDescTbl().
debugString());
139 super.computeStats(analyzer);
145 List<String> orderByElementStrs = Lists.newArrayList();
147 orderByElementStrs.add(element.toSql());
149 return Objects.toStringHelper(
this)
153 .add(
"orderByElements", Joiner.on(
", ").join(orderByElementStrs))
157 .add(
"partitionByEq",
161 .addValue(super.debugString())
167 msg.node_type = TPlanNodeType.ANALYTIC_EVAL_NODE;
168 msg.analytic_node =
new TAnalyticNode();
169 msg.analytic_node.setIntermediate_tuple_id(intermediateTupleDesc_.getId().asInt());
170 msg.analytic_node.setOutput_tuple_id(outputTupleDesc_.getId().asInt());
172 msg.analytic_node.setOrder_by_exprs(
174 msg.analytic_node.setAnalytic_functions(Expr.treesToThrift(
analyticFnCalls_));
177 msg.analytic_node.setWindow(AnalyticWindow.DEFAULT_WINDOW.toThrift());
181 msg.analytic_node.setWindow(analyticWindow_.toThrift());
184 msg.analytic_node.setPartition_by_eq(partitionByEq_.treeToThrift());
187 msg.analytic_node.setOrder_by_eq(orderByEq_.treeToThrift());
190 msg.analytic_node.setBuffered_tuple_id(bufferedTupleDesc_.getId().asInt());
196 TExplainLevel detailLevel) {
197 StringBuilder output =
new StringBuilder();
200 if (detailLevel.ordinal() >= TExplainLevel.STANDARD.ordinal()) {
201 output.append(detailPrefix +
"functions: ");
202 List<String> strings = Lists.newArrayList();
204 strings.add(fnCall.toSql());
206 output.append(Joiner.on(
", ").join(strings));
210 output.append(detailPrefix +
"partition by: ");
213 strings.add(partitionExpr.toSql());
215 output.append(Joiner.on(
", ").join(strings));
220 output.append(detailPrefix +
"order by: ");
223 strings.add(element.toSql());
225 output.append(Joiner.on(
", ").join(strings));
230 output.append(detailPrefix +
"window: ");
231 output.append(analyticWindow_.toSql());
240 return output.toString();
246 "PlanNode must be placed into a fragment before calling this method.");
final Expr partitionByEq_
void toThrift(TPlanNode msg)
List< Expr > getPartitionExprs()
final AnalyticWindow analyticWindow_
List< Expr > analyticFnCalls_
AnalyticEvalNode(PlanNodeId id, PlanNode input, List< TupleId > stmtTupleIds, List< Expr > analyticFnCalls, List< Expr > partitionExprs, List< OrderByElement > orderByElements, AnalyticWindow analyticWindow, TupleDescriptor logicalTupleDesc, TupleDescriptor intermediateTupleDesc, TupleDescriptor outputTupleDesc, ExprSubstitutionMap logicalToPhysicalSmap, Expr partitionByEq, Expr orderByEq, TupleDescriptor bufferedTupleDesc)
final TupleDescriptor bufferedTupleDesc_
ExprSubstitutionMap getCombinedChildSmap()
List< OrderByElement > getOrderByElements()
String getExplainString()
final List< Expr > partitionExprs_
final TupleDescriptor logicalTupleDesc_
ArrayList< TupleId > getTupleIds()
final List< TupleId > stmtTupleIds_
final ExprSubstitutionMap logicalToPhysicalSmap_
List< Expr > substitutedPartitionExprs_
final TupleDescriptor intermediateTupleDesc_
final TupleDescriptor outputTupleDesc_
void createDefaultSmap(Analyzer analyzer)
void computeMemLayout(Analyzer analyzer)
String getNodeExplainString(String prefix, String detailPrefix, TExplainLevel detailLevel)
void computeStats(Analyzer analyzer)
void init(Analyzer analyzer)
void computeCosts(TQueryOptions queryOptions)
List< OrderByElement > orderByElements_
final String getDisplayLabel()
ExprSubstitutionMap outputSmap_