15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.List;
28 import com.cloudera.impala.common.Pair;
30 import com.cloudera.impala.thrift.TAccessEvent;
31 import com.cloudera.impala.thrift.TCatalogObjectType;
32 import com.google.common.base.Joiner;
33 import com.google.common.base.Preconditions;
34 import com.google.common.collect.Lists;
35 import com.google.common.collect.Sets;
89 aliases_ =
new String[] { alias.toLowerCase() };
102 Preconditions.checkNotNull(other);
103 this.rawPath_ = other.rawPath_;
104 this.resolvedPath_ = other.resolvedPath_;
105 this.aliases_ = other.aliases_;
106 this.hasExplicitAlias_ = other.hasExplicitAlias_;
107 this.joinOp_ = other.joinOp_;
109 (other.joinHints_ != null) ? Lists.newArrayList(other.
joinHints_) : null;
110 this.usingColNames_ =
111 (other.usingColNames_ != null) ? Lists.newArrayList(other.
usingColNames_) : null;
112 this.onClause_ = (other.onClause_ != null) ? other.
onClause_.
clone().reset() : null;
113 this.isAnalyzed_ =
false;
121 if (!analyzer.hasMissingTbls()) {
127 .onTable(rawPath_.get(0),
rawPath_.get(1))
131 .onTable(analyzer.getDefaultDb(),
rawPath_.get(0))
137 "Failed to load metadata for table: '%s'", Joiner.on(
".").join(
rawPath_)), e);
142 Table table = resolvedPath_.getRootTable();
143 if (table instanceof
View) {
144 View view = (View) table;
146 analyzer.addAccessEvent(
new TAccessEvent(
151 analyzer.addAccessEvent(
new TAccessEvent(
157 TableName tableName = table.getTableName();
159 .onTable(tableName.getDb(), tableName.
getTbl())
182 this.joinOp_ = other.joinOp_;
183 this.joinHints_ = other.joinHints_;
184 this.onClause_ = other.onClause_;
185 this.usingColNames_ = other.usingColNames_;
231 return resolvedPath_.getRootTable();
238 public void setUsingClause(List<String> colNames) { this.usingColNames_ = colNames; }
241 public void setJoinHints(ArrayList<String> hints) { this.joinHints_ = hints; }
245 public boolean isResolved() {
return !getClass().equals(TableRef.class); }
253 Preconditions.checkState(
desc_ != null);
263 Preconditions.checkState(
desc_ != null);
264 return desc_.getId();
270 Preconditions.checkNotNull(
desc_);
271 return desc_.getId().asList();
280 List<TupleId> result =
281 Lists.newArrayList(leftTblRef_.getAllMaterializedTupleIds());
295 List<TupleId> result = leftTblRef_.getAllTupleIds();
296 result.add(desc_.getId());
299 return Lists.newArrayList(desc_.getId());
306 if (hint.equalsIgnoreCase(
"BROADCAST")) {
318 analyzer.setHasPlanHints();
319 }
else if (hint.equalsIgnoreCase(
"SHUFFLE")) {
327 analyzer.setHasPlanHints();
329 analyzer.addWarning(
"JOIN hint not recognized: " + hint);
340 Preconditions.checkState(
desc_ != null);
355 Lists.newArrayList(colName.toLowerCase()));
358 "unknown column " + colName +
" for alias "
362 Lists.newArrayList(colName.toLowerCase()));
365 "unknown column " + colName +
" for alias "
374 onClause_ = CompoundPredicate.createConjunction(eqPred,
onClause_);
382 analyzer.registerOuterJoinedTids(
getId().asList(),
this);
386 analyzer.registerOuterJoinedTids(leftTblRef_.getAllTupleIds(),
this);
390 analyzer.registerFullOuterJoinedTids(leftTblRef_.getAllTupleIds(),
this);
391 analyzer.registerFullOuterJoinedTids(
getId().asList(),
this);
394 TupleId semiJoinedTupleId = null;
398 analyzer.registerSemiJoinedTid(
getId(),
this);
399 semiJoinedTupleId =
getId();
404 analyzer.registerSemiJoinedTid(leftTblRef_.getId(),
this);
405 semiJoinedTupleId = leftTblRef_.getId();
410 analyzer.setVisibleSemiJoinedTuple(semiJoinedTupleId);
411 onClause_.analyze(analyzer);
412 analyzer.setVisibleSemiJoinedTuple(null);
413 onClause_.checkReturnsBool(
"ON clause",
true);
416 "aggregate function not allowed in ON clause: " +
toSql());
420 "analytic expression not allowed in ON clause: " +
toSql());
422 Set<TupleId> onClauseTupleIds = Sets.newHashSet();
429 analyzer.registerOnClauseConjuncts(e,
this);
430 List<TupleId> tupleIds = Lists.newArrayList();
431 e.getIds(tupleIds, null);
432 onClauseTupleIds.addAll(tupleIds);
434 onClauseTupleIds_.addAll(onClauseTupleIds);
449 Preconditions.checkState(leftTblRef_.leftTblRef_ == null);
453 for (Pair<TableRef, PlanNode> refPlan: refPlans) {
454 if (refPlan.first.leftTblRef_ ==
this) {
460 leftTblRef_.setJoinOp(
getJoinOp().invert());
461 leftTblRef_.setLeftTblRef(
this);
469 String aliasSql = null;
471 if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
473 if (
resolvedPath_ != null) path = resolvedPath_.getFullyQualifiedRawPath();
474 return ToSqlUtils.getPathSql(
path) + ((aliasSql != null) ?
" " + aliasSql :
"");
485 StringBuilder output =
new StringBuilder(
" " +
joinOp_.
toString() +
" ");
489 output.append(
" USING (").append(Joiner.on(
", ").join(
usingColNames_)).append(
")");
493 return output.toString();
void invertOuterJoinState(TableRef oldRhsTbl, TableRef newRhsTbl)
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
List< TupleId > onClauseTupleIds_
Privilege getPrivilegeRequirement()
static com.google.common.base.Predicate< Expr > isAggregatePredicate()
void setJoinHints(ArrayList< String > hints)
List< TupleId > getAllTupleIds()
boolean isPartitionedJoin_
void analyze(Analyzer analyzer)
boolean isPartitionedJoin()
ArrayList< String > getJoinHints()
boolean hasExplicitAlias_
boolean isBroadcastJoin()
void analyzeJoinHints(Analyzer analyzer)
void setJoinAttrs(TableRef other)
List< TupleId > getMaterializedTupleIds()
TableRef(List< String > path, String alias)
ArrayList< String > joinHints_
void setUsingClause(List< String > colNames)
void setJoinOp(JoinOperator op)
void invertJoin(List< Pair< TableRef, PlanNode >> refPlans, Analyzer analyzer)
List< String > getUsingClause()
List< TupleId > getOnClauseTupleIds()
static ArrayList< String > createRawPath(String rootAlias, String fieldName)
TupleDescriptor getDesc()
NULL_AWARE_LEFT_ANTI_JOIN
void setLeftTblRef(TableRef leftTblRef)
List< String > usingColNames_
TupleDescriptor createTupleDescriptor(Analyzer analyzer)
void analyzeJoin(Analyzer analyzer)
boolean hasExplicitAlias()
List< Expr > getConjuncts()
String getExplicitAlias()
List< TupleId > getAllMaterializedTupleIds()