15 package com.cloudera.impala.planner;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
24 import com.cloudera.impala.thrift.TExchangeNode;
25 import com.cloudera.impala.thrift.TExplainLevel;
26 import com.cloudera.impala.thrift.TPlanNode;
27 import com.cloudera.impala.thrift.TPlanNodeType;
28 import com.cloudera.impala.thrift.TSortInfo;
29 import com.google.common.base.Preconditions;
30 import com.google.common.collect.Lists;
31 import com.google.common.collect.Sets;
46 private final static Logger
LOG = LoggerFactory.getLogger(ExchangeNode.class);
57 super(
id,
"EXCHANGE");
64 if (!children_.isEmpty()) {
65 Preconditions.checkState(
limit_ == node.limit_);
66 Preconditions.checkState(tupleIds_.equals(node.tupleIds_));
67 Preconditions.checkState(nullableTupleIds_.equals(node.nullableTupleIds_));
71 tupleIds_ = Lists.newArrayList(node.tupleIds_);
74 if (copyConjuncts) conjuncts_.addAll(Expr.cloneList(node.conjuncts_));
80 Preconditions.checkState(!children_.isEmpty(),
81 "ExchangeNode must have at least one child");
84 if (child.getCardinality() == -1) {
125 TExplainLevel detailLevel) {
126 StringBuilder output =
new StringBuilder();
127 output.append(String.format(
"%s%s [%s]\n", prefix,
131 output.append(detailPrefix +
"offset: ").append(
offset_).append(
"\n");
134 if (
mergeInfo_ != null && detailLevel.ordinal() > TExplainLevel.MINIMAL.ordinal()) {
135 output.append(detailPrefix +
"order by: ");
136 for (
int i = 0; i < mergeInfo_.getOrderingExprs().size(); ++i) {
137 if (i > 0) output.append(
", ");
138 output.append(mergeInfo_.getOrderingExprs().
get(i).toSql() +
" ");
139 output.append(mergeInfo_.getIsAscOrder().
get(i) ?
"ASC" :
"DESC");
141 Boolean nullsFirstParam = mergeInfo_.getNullsFirstParams().
get(i);
142 if (nullsFirstParam != null) {
143 output.append(nullsFirstParam ?
" NULLS FIRST" :
" NULLS LAST");
148 return output.toString();
155 Preconditions.checkState(!children_.isEmpty());
156 DataSink sink = getChild(0).getFragment().getSink();
157 if (sink == null)
return "";
160 if (!streamSink.getOutputPartition().isPartitioned() &&
172 Preconditions.checkState(!children_.isEmpty(),
173 "ExchangeNode must have at least one child");
174 msg.node_type = TPlanNodeType.EXCHANGE_NODE;
175 msg.exchange_node =
new TExchangeNode();
177 msg.exchange_node.addToInput_row_tuples(tid.asInt());
181 TSortInfo sortInfo =
new TSortInfo(
183 mergeInfo_.getNullsFirst());
184 msg.exchange_node.setSort_info(sortInfo);
185 msg.exchange_node.setOffset(
offset_);
String getNodeExplainString(String prefix, String detailPrefix, TExplainLevel detailLevel)
ExchangeNode(PlanNodeId id)
List< Boolean > getIsAscOrder()
static List< TExpr > treesToThrift(List<?extends Expr > exprs)
ArrayList< TupleId > tupleIds_
String getExplainString()
void addChild(PlanNode node, boolean copyConjuncts)
void toThrift(TPlanNode msg)
void setMergeInfo(SortInfo info, long offset)
PlanFragment getFragment()
Set< TupleId > nullableTupleIds_
String getDisplayLabelDetail()
uint8_t offset[7 *64-sizeof(uint64_t)]
void computeStats(Analyzer analyzer)
List< Expr > getOrderingExprs()
final String getDisplayLabel()
static long addCardinalities(long a, long b)