Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SlotDescriptor.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.analysis;
16 
17 import java.util.Collections;
18 import java.util.List;
19 
23 import com.cloudera.impala.thrift.TSlotDescriptor;
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 
29 public class SlotDescriptor {
30  private final SlotId id_;
31  private final TupleDescriptor parent_;
32 
33  // Resolved path to the column/field corresponding to this slot descriptor, if any,
34  // Only set for slots that represent a column/field.
35  private Path path_;
36  private Type type_;
37 
38  // for SlotRef.toSql() in the absence of a path
39  private String label_;
40 
41  // Expr(s) materialized into this slot; multiple exprs for unions. Should be empty if
42  // column_ is set.
43  private List<Expr> sourceExprs_ = Lists.newArrayList();
44 
45  // if false, this slot doesn't need to be materialized in parent tuple
46  // (and physical layout parameters are invalid)
47  private boolean isMaterialized_ = false;
48 
49  // if false, this slot cannot be NULL
50  private boolean isNullable_ = true;
51 
52  // physical layout parameters
53  private int byteSize_;
54  private int byteOffset_; // within tuple
55  private int nullIndicatorByte_; // index into byte array
56  private int nullIndicatorBit_; // index within byte
57  private int slotIdx_; // index within tuple struct
58 
59  private ColumnStats stats_; // only set if 'column' isn't set
60 
62  id_ = id;
63  parent_ = parent;
64  byteOffset_ = -1; // invalid
65  }
66 
68  id_ = id;
69  parent_ = parent;
70  type_ = src.type_;
71  path_ = src.path_;
72  label_ = src.label_;
73  sourceExprs_ = src.sourceExprs_;
74  isMaterialized_ = src.isMaterialized_;
75  isNullable_ = src.isNullable_;
76  byteSize_ = src.byteSize_;
77  byteOffset_ = src.byteOffset_;
78  nullIndicatorByte_ = src.nullIndicatorByte_;
79  nullIndicatorBit_ = src.nullIndicatorBit_;
80  slotIdx_ = src.slotIdx_;
81  stats_ = src.stats_;
82  }
83 
84  public int getNullIndicatorByte() { return nullIndicatorByte_; }
85  public void setNullIndicatorByte(int nullIndicatorByte) {
86  this.nullIndicatorByte_ = nullIndicatorByte;
87  }
88  public int getNullIndicatorBit() { return nullIndicatorBit_; }
89  public void setNullIndicatorBit(int nullIndicatorBit) {
90  this.nullIndicatorBit_ = nullIndicatorBit;
91  }
92  public SlotId getId() { return id_; }
93  public TupleDescriptor getParent() { return parent_; }
94  public Type getType() { return type_; }
95  public void setType(Type type) { type_ = type; }
96  public boolean isMaterialized() { return isMaterialized_; }
97  public void setIsMaterialized(boolean value) { isMaterialized_ = value; }
98  public boolean getIsNullable() { return isNullable_; }
99  public void setIsNullable(boolean value) { isNullable_ = value; }
100  public int getByteSize() { return byteSize_; }
101  public void setByteSize(int byteSize) { this.byteSize_ = byteSize; }
102  public int getByteOffset() { return byteOffset_; }
103  public void setByteOffset(int byteOffset) { this.byteOffset_ = byteOffset; }
104  public void setSlotIdx(int slotIdx) { this.slotIdx_ = slotIdx; }
105  public String getLabel() { return label_; }
106  public void setLabel(String label) { label_ = label; }
107  public void setSourceExprs(List<Expr> exprs) { sourceExprs_ = exprs; }
108  public void setSourceExpr(Expr expr) { sourceExprs_ = Collections.singletonList(expr); }
109  public void addSourceExpr(Expr expr) { sourceExprs_.add(expr); }
110  public List<Expr> getSourceExprs() { return sourceExprs_; }
111  public void setStats(ColumnStats stats) { this.stats_ = stats; }
112 
113  public void setPath(Path path) {
114  Preconditions.checkNotNull(path);
115  Preconditions.checkNotNull(path.getRootDesc());
116  Preconditions.checkState(path.getRootDesc() == parent_);
117  path_ = path;
118  type_ = path_.destType();
119  label_ = Joiner.on(".").join(path.getRawPath());
120  }
121 
122  public Path getPath() { return path_; }
123 
124  public Column getColumn() {
125  if (path_ == null) return null;
126  return path_.destColumn();
127  }
128 
130  if (stats_ == null) {
131  Column c = getColumn();
132  if (c != null) {
133  stats_ = c.getStats();
134  } else {
135  stats_ = new ColumnStats(type_);
136  }
137  }
138  return stats_;
139  }
140 
144  public List<Integer> getAbsolutePath() {
145  Preconditions.checkNotNull(parent_);
146  // A slot descriptor typically only has a path if the parent also has one.
147  // However, we sometimes materialize inline-view tuples when generating plan trees
148  // with EmptySetNode portions. In that case, a slot descriptor could have a non-empty
149  // path pointing into the inline-view tuple (which has no path).
150  if (path_ == null || parent_.getPath() == null) return Collections.emptyList();
151  return Lists.newArrayList(path_.getAbsolutePath());
152  }
153 
154  public TSlotDescriptor toThrift() {
155  List<Integer> slotPath = getAbsolutePath();
156  TSlotDescriptor result = new TSlotDescriptor(
157  id_.asInt(), parent_.getId().asInt(), type_.toThrift(),
160  return result;
161  }
162 
163  public String debugString() {
164  String pathStr = (path_ == null) ? "null" : path_.toString();
165  String typeStr = (type_ == null ? "null" : type_.toString());
166  return Objects.toStringHelper(this)
167  .add("id", id_.asInt())
168  .add("path", pathStr)
169  .add("type", typeStr)
170  .add("materialized", isMaterialized_)
171  .add("byteSize", byteSize_)
172  .add("byteOffset", byteOffset_)
173  .add("nullIndicatorByte", nullIndicatorByte_)
174  .add("nullIndicatorBit", nullIndicatorBit_)
175  .add("slotIdx", slotIdx_)
176  .add("stats", stats_)
177  .toString();
178  }
179 }
void setNullIndicatorByte(int nullIndicatorByte)
void setNullIndicatorBit(int nullIndicatorBit)
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
SlotDescriptor(SlotId id, TupleDescriptor parent, SlotDescriptor src)
SlotDescriptor(SlotId id, TupleDescriptor parent)
List< String > getRawPath()
Definition: Path.java:240