15 package com.cloudera.impala.analysis;
17 import java.util.ArrayList;
18 import java.util.HashSet;
19 import java.util.List;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
29 import com.google.common.base.Preconditions;
30 import com.google.common.collect.Lists;
31 import com.google.common.collect.Sets;
38 private final static Logger
LOG = LoggerFactory.getLogger(SelectStmt.class);
70 Preconditions.checkNotNull(queryStmt);
76 this(alias, queryStmt);
91 view_.getTableName().toString().toLowerCase(),
view_.
getName().toLowerCase()
100 Preconditions.checkNotNull(other.queryStmt_);
101 queryStmt_ = other.queryStmt_.clone();
118 boolean isCatalogView = (
view_ != null && !view_.isLocalView());
124 inlineViewAnalyzer_.setAuthErrMsg(
125 String.format(
"User '%s' does not have privileges to " +
126 "EXPLAIN this statement.", analyzer.getUser().getName()));
130 inlineViewAnalyzer_.setEnablePrivChecks(
false);
134 inlineViewAnalyzer_.setUseHiveColLabels(
135 isCatalogView ?
true : analyzer.useHiveColLabels());
138 Preconditions.checkState(
139 explicitColLabels_.size() == queryStmt_.getColLabels().size());
142 inlineViewAnalyzer_.setHasLimitOffsetClause(
143 queryStmt_.hasLimit() || queryStmt_.hasOffset());
145 desc_ = analyzer.registerTableRef(
this);
150 Preconditions.checkState(queryStmt_ instanceof
SelectStmt);
151 Preconditions.checkState(((
SelectStmt) queryStmt_).getTableRefs().isEmpty());
152 desc_.setIsMaterialized(
true);
153 materializedTupleIds_.add(desc_.getId());
169 Expr colExpr = queryStmt_.getResultExprs().
get(i);
170 Path p =
new Path(desc_, Lists.newArrayList(colName));
171 Preconditions.checkState(p.resolve());
173 slotDesc.setSourceExpr(colExpr);
174 slotDesc.setStats(ColumnStats.fromExpr(colExpr));
176 smap_.put(slotRef, colExpr);
177 baseTblSmap_.put(slotRef, queryStmt_.getBaseTblResultExprs().
get(i));
179 analyzer.createAuxEquivPredicate(
new SlotRef(slotDesc), colExpr.clone());
182 LOG.trace(
"inline view " +
getUniqueAlias() +
" smap: " + smap_.debugString());
184 baseTblSmap_.debugString());
197 || !((SelectStmt) queryStmt_).hasAnalyticInfo()) {
200 AnalyticInfo analyticInfo = ((SelectStmt) queryStmt_).getAnalyticInfo();
201 return analyticInfo.getCommonPartitionExprs().contains(e);
213 Preconditions.checkState(numColLabels > 0);
214 HashSet<String> uniqueColAliases = Sets.newHashSetWithExpectedSize(numColLabels);
215 ArrayList<StructField> fields = Lists.newArrayListWithCapacity(numColLabels);
216 for (
int i = 0; i < numColLabels; ++i) {
218 Expr selectItemExpr = queryStmt_.getResultExprs().
get(i);
222 if (!uniqueColAliases.add(colAlias)) {
224 colAlias +
"'" +
" in inline view " +
"'" +
getUniqueAlias() +
"'");
232 result.setIsMaterialized(
false);
240 Preconditions.checkState(materializedTupleIds_.size() > 0);
261 Preconditions.checkState(
getAnalyzer().containsSubquery());
269 return queryStmt_.getColLabels();
279 String aliasSql = null;
281 if (alias != null) aliasSql = ToSqlUtils.getIdentSql(alias);
283 return view_.getTableName().
toSql() + (aliasSql == null ?
"" :
" " + aliasSql);
285 Preconditions.checkNotNull(aliasSql);
286 StringBuilder sql =
new StringBuilder()
288 .append(queryStmt_.toSql())
295 if (i > 0) sql.append(
", ");
300 return sql.toString();
ExprSubstitutionMap getBaseTblSmap()
TupleDescriptor createTupleDescriptor(Analyzer analyzer)
InlineViewRef(View view, TableRef origTblRef)
final ArrayList< TupleId > materializedTupleIds_
List< TupleId > getMaterializedTupleIds()
InlineViewRef(String alias, QueryStmt queryStmt, List< String > colLabels)
List< String > getExplicitColLabels()
List< String > explicitColLabels_
Analyzer inlineViewAnalyzer_
void analyze(Analyzer analyzer)
void setJoinAttrs(TableRef other)
boolean createAuxPredicate(Expr e)
final ExprSubstitutionMap baseTblSmap_
List< String > getColLabels()
ExprSubstitutionMap getSmap()
void setRewrittenViewStmt(QueryStmt stmt)
void analyzeJoin(Analyzer analyzer)
boolean hasExplicitAlias()
final ExprSubstitutionMap smap_
InlineViewRef(String alias, QueryStmt queryStmt)
String getExplicitAlias()
InlineViewRef(InlineViewRef other)