Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ScanNode.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 
21 import com.cloudera.impala.thrift.TExplainLevel;
22 import com.cloudera.impala.thrift.TNetworkAddress;
23 import com.cloudera.impala.thrift.TScanRangeLocations;
24 import com.google.common.base.Joiner;
25 import com.google.common.base.Objects;
26 import com.google.common.base.Preconditions;
27 import com.google.common.collect.Lists;
28 
32 abstract public class ScanNode extends PlanNode {
33  protected final TupleDescriptor desc_;
34 
35  // Total number of rows this node is expected to process
36  protected long inputCardinality_ = -1;
37 
38  // Counter indicating if partitions have missing statistics
39  protected int numPartitionsMissingStats_ = 0;
40 
41  // List of scan-range locations. Populated in init().
42  protected List<TScanRangeLocations> scanRanges_;
43 
44  public ScanNode(PlanNodeId id, TupleDescriptor desc, String displayName) {
45  super(id, desc.getId().asList(), displayName);
46  desc_ = desc;
47  }
48 
49  public TupleDescriptor getTupleDesc() { return desc_; }
50 
54  public List<TScanRangeLocations> getScanRangeLocations() {
55  Preconditions.checkNotNull(scanRanges_, "Need to call init() first.");
56  return scanRanges_;
57  }
58 
59  @Override
60  protected String debugString() {
61  return Objects.toStringHelper(this)
62  .add("tid", desc_.getId().asInt())
63  .add("tblName", desc_.getTable().getFullName())
64  .add("keyRanges", "")
65  .addValue(super.debugString())
66  .toString();
67  }
68 
75  protected String getStatsExplainString(String prefix, TExplainLevel detailLevel) {
76  StringBuilder output = new StringBuilder();
77  // Table stats.
78  if (desc_.getTable().getNumRows() == -1) {
79  output.append(prefix + "table stats: unavailable");
80  } else {
81  output.append(prefix + "table stats: " + desc_.getTable().getNumRows() +
82  " rows total");
84  output.append(" (" + numPartitionsMissingStats_ + " partition(s) missing stats)");
85  }
86  }
87  output.append("\n");
88 
89  // Column stats.
90  List<String> columnsMissingStats = Lists.newArrayList();
91  for (SlotDescriptor slot: desc_.getSlots()) {
92  if (!slot.getStats().hasStats() && slot.getColumn() != null) {
93  columnsMissingStats.add(slot.getColumn().getName());
94  }
95  }
96  if (columnsMissingStats.isEmpty()) {
97  output.append(prefix + "column stats: all");
98  } else if (columnsMissingStats.size() == desc_.getSlots().size()) {
99  output.append(prefix + "column stats: unavailable");
100  } else {
101  output.append(String.format("%scolumns missing stats: %s", prefix,
102  Joiner.on(", ").join(columnsMissingStats)));
103  }
104  return output.toString();
105  }
106 
111  public boolean isTableMissingStats() {
113  }
114 
115  public boolean isTableMissingTableStats() {
116  if (desc_.getTable().getNumRows() == -1) return true;
117  return numPartitionsMissingStats_ > 0;
118  }
119 
120  public boolean isTableMissingColumnStats() {
121  for (SlotDescriptor slot: desc_.getSlots()) {
122  if (!slot.getStats().hasStats()) return true;
123  }
124  return false;
125  }
126 
127 
132  protected static TNetworkAddress addressToTNetworkAddress(String address) {
133  TNetworkAddress result = new TNetworkAddress();
134  String[] hostPort = address.split(":");
135  result.hostname = hostPort[0];
136  result.port = Integer.parseInt(hostPort[1]);
137  return result;
138  }
139 
140  @Override
141  public long getInputCardinality() {
142  if (getConjuncts().isEmpty() && hasLimit()) return getLimit();
143  return inputCardinality_;
144  }
145 }
static TNetworkAddress addressToTNetworkAddress(String address)
Definition: ScanNode.java:132
String getStatsExplainString(String prefix, TExplainLevel detailLevel)
Definition: ScanNode.java:75
List< TScanRangeLocations > getScanRangeLocations()
Definition: ScanNode.java:54
final TupleDescriptor desc_
Definition: ScanNode.java:33
ScanNode(PlanNodeId id, TupleDescriptor desc, String displayName)
Definition: ScanNode.java:44
List< TScanRangeLocations > scanRanges_
Definition: ScanNode.java:42