Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SelectNode.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.planner;
16 
17 import java.util.List;
18 
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 
25 import com.cloudera.impala.thrift.TExplainLevel;
26 import com.cloudera.impala.thrift.TPlanNode;
27 import com.cloudera.impala.thrift.TPlanNodeType;
28 import com.google.common.base.Preconditions;
29 
33 public class SelectNode extends PlanNode {
34  private final static Logger LOG = LoggerFactory.getLogger(SelectNode.class);
35 
36  protected SelectNode(PlanNodeId id, PlanNode child, List<Expr> conjuncts) {
37  super(id, child.getTupleIds(), "SELECT");
38  addChild(child);
39  this.tblRefIds_ = child.tblRefIds_;
40  this.nullableTupleIds_ = child.nullableTupleIds_;
41  conjuncts_.addAll(conjuncts);
42  }
43 
44  @Override
45  protected void toThrift(TPlanNode msg) {
46  msg.node_type = TPlanNodeType.SELECT_NODE;
47  }
48 
49  @Override
50  public void init(Analyzer analyzer) throws InternalException {
51  analyzer.markConjunctsAssigned(conjuncts_);
52  computeStats(analyzer);
53  createDefaultSmap(analyzer);
54  }
55 
56  @Override
57  public void computeStats(Analyzer analyzer) {
58  super.computeStats(analyzer);
59  if (getChild(0).cardinality_ == -1) {
60  cardinality_ = -1;
61  } else {
62  cardinality_ =
63  Math.round(((double) getChild(0).cardinality_) * computeSelectivity());
64  Preconditions.checkState(cardinality_ >= 0);
65  }
66  LOG.debug("stats Select: cardinality=" + Long.toString(cardinality_));
67  }
68 
69  @Override
70  protected String getNodeExplainString(String prefix, String detailPrefix,
71  TExplainLevel detailLevel) {
72  StringBuilder output = new StringBuilder();
73  output.append(String.format("%s%s:%s\n", prefix, id_.toString(), displayName_));
74  if (detailLevel.ordinal() >= TExplainLevel.STANDARD.ordinal()) {
75  if (!conjuncts_.isEmpty()) {
76  output.append(detailPrefix + "predicates: " +
78  }
79  }
80  return output.toString();
81  }
82 }
String getNodeExplainString(String prefix, String detailPrefix, TExplainLevel detailLevel)
Definition: SelectNode.java:70
SelectNode(PlanNodeId id, PlanNode child, List< Expr > conjuncts)
Definition: SelectNode.java:36
ArrayList< TupleId > getTupleIds()
Definition: PlanNode.java:196
void createDefaultSmap(Analyzer analyzer)
Definition: PlanNode.java:425
void computeStats(Analyzer analyzer)
Definition: SelectNode.java:57