15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.List;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
28 import com.cloudera.impala.thrift.TExprNode;
29 import com.cloudera.impala.thrift.TExprNodeType;
30 import com.cloudera.impala.thrift.TSlotRef;
31 import com.google.common.base.Joiner;
32 import com.google.common.base.Objects;
33 import com.google.common.base.Preconditions;
36 private final static Logger
LOG = LoggerFactory.getLogger(SlotRef.class);
44 public SlotRef(ArrayList<String> rawPath) {
57 label_ = ToSqlUtils.getIdentSql(alias.toLowerCase());
66 rawPath_ = desc.getPath().getRawPath();
72 type_ = desc.getType();
73 String alias = desc.getParent().getAlias();
93 super.analyze(analyzer);
94 Path resolvedPath = null;
99 Preconditions.checkState(
false);
101 Preconditions.checkNotNull(resolvedPath);
102 desc_ = analyzer.registerSlotRef(resolvedPath);
103 type_ = desc_.getType();
104 if (!type_.isSupported()) {
106 + type_.toSql() +
"' in '" +
toSql() +
"'.");
108 if (type_.isInvalid()) {
121 Preconditions.checkNotNull(
desc_);
127 Preconditions.checkNotNull(
desc_);
128 return desc_.getId();
133 return desc_.getPath();
140 return "<slot " + Integer.toString(desc_.getId().asInt()) +
">";
145 msg.node_type = TExprNodeType.SLOT_REF;
146 msg.slot_ref =
new TSlotRef(
desc_.
getId().asInt());
147 Preconditions.checkState(desc_.getParent().isMaterialized(),
148 String.format(
"Illegal reference to non-materialized tuple: tid=%s",
149 desc_.getParent().
getId()));
151 Preconditions.checkState(desc_.isMaterialized(),
152 String.format(
"Illegal reference to non-materialized slot: tid=%s sid=%s",
155 Preconditions.checkState(desc_.getByteOffset() != -1,
156 String.format(
"Missing memory layout for tuple with tid=%s",
162 Objects.ToStringHelper toStrHelper = Objects.toStringHelper(
this);
163 if (
rawPath_ != null) toStrHelper.add(
"path", Joiner.on(
'.').join(
rawPath_));
164 toStrHelper.add(
"type", type_.toSql());
165 String idStr = (
desc_ == null ?
"null" : Integer.toString(desc_.getId().asInt()));
166 toStrHelper.add(
"id", idStr);
167 return toStrHelper.toString();
173 return Objects.hashCode(Joiner.on(
'.').join(
rawPath_).toLowerCase());
178 if (!super.equals(obj))
return false;
185 if ((
label_ == null) != (other.label_ == null))
return false;
186 if (!
label_.equalsIgnoreCase(other.
label_))
return false;
192 Preconditions.checkState(
desc_ != null);
202 return slotIds.contains(desc_.getId());
207 Preconditions.checkState(type_.isValid());
208 Preconditions.checkState(
desc_ != null);
209 if (slotIds != null) slotIds.add(desc_.getId());
210 if (tupleIds != null) tupleIds.add(desc_.getParent().
getId());
219 return "tid=" + desc_.getParent().
getId() +
" sid=" + desc_.getId();
221 return "no desc set";
228 return NullLiteral.create(targetType);
230 return super.uncheckedCastTo(targetType);
void getIdsHelper(Set< TupleId > tupleIds, Set< SlotId > slotIds)
boolean equals(Object obj)
final List< String > rawPath_
Expr uncheckedCastTo(Type targetType)
SlotRef(SlotDescriptor desc)
void toThrift(TExprNode msg)
boolean isBoundBySlotIds(List< SlotId > slotIds)
long getNumDistinctValues()
SlotRef(ArrayList< String > rawPath)
boolean isBoundByTupleIds(List< TupleId > tids)
void analyze(Analyzer analyzer)
TupleDescriptor getParent()
static double DEFAULT_SELECTIVITY