Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
com.cloudera.impala.analysis.SelectStmt Class Reference
Inheritance diagram for com.cloudera.impala.analysis.SelectStmt:
Collaboration diagram for com.cloudera.impala.analysis.SelectStmt:

Public Member Functions

SelectList getSelectList ()
 
Expr getHavingPred ()
 
List< TableRefgetTableRefs ()
 
boolean hasWhereClause ()
 
boolean hasGroupByClause ()
 
Expr getWhereClause ()
 
void setWhereClause (Expr whereClause)
 
AggregateInfo getAggInfo ()
 
boolean hasAggInfo ()
 
AnalyticInfo getAnalyticInfo ()
 
boolean hasAnalyticInfo ()
 
ArrayList< String > getColLabels ()
 
ExprSubstitutionMap getBaseTblSmap ()
 
ColumnAliasGenerator getColumnAliasGenerator ()
 
TableAliasGenerator getTableAliasGenerator ()
 
void analyze (Analyzer analyzer) throws AnalysisException
 
void materializeRequiredSlots (Analyzer analyzer)
 
List< TupleIdgetTableRefIds ()
 
String toSql ()
 
void getMaterializedTupleIds (ArrayList< TupleId > tupleIdList)
 
QueryStmt clone ()
 
boolean returnsSingleRow ()
 
Analyzer getAnalyzer ()
 
void setWithClause (WithClause withClause)
 
boolean hasWithClause ()
 
WithClause getWithClause ()
 
boolean hasOrderByClause ()
 
boolean hasLimit ()
 
long getLimit ()
 
boolean hasOffset ()
 
long getOffset ()
 
SortInfo getSortInfo ()
 
boolean evaluateOrderBy ()
 
ArrayList< ExprgetResultExprs ()
 
ArrayList< ExprgetBaseTblResultExprs ()
 
void setLimit (long limit) throws AnalysisException
 
ArrayList< OrderByElementcloneOrderByElements ()
 
WithClause cloneWithClause ()
 
void setIsExplain ()
 
boolean isExplain ()
 

Protected Member Functions

void resolveInlineViewRefs (Analyzer analyzer) throws AnalysisException
 
void createSortInfo (Analyzer analyzer) throws AnalysisException
 
void createSortTupleInfo (Analyzer analyzer)
 
Expr getFirstAmbiguousAlias (List< Expr > exprs)
 
void substituteOrdinals (List< Expr > exprs, String errorPrefix, Analyzer analyzer) throws AnalysisException
 
void materializeSlots (Analyzer analyzer, List< Expr > exprs)
 

Protected Attributes

SelectList selectList_
 
final ArrayList< String > colLabels_
 
final List< TableReftableRefs_
 
Expr whereClause_
 
ArrayList< ExprgroupingExprs_
 
final Expr havingClause_
 
String sqlString_
 
WithClause withClause_
 
ArrayList< OrderByElementorderByElements_
 
LimitElement limitElement_
 
ArrayList< ExprresultExprs_ = Lists.newArrayList()
 
ArrayList< ExprbaseTblResultExprs_ = Lists.newArrayList()
 
final ExprSubstitutionMap aliasSmap_ = new ExprSubstitutionMap()
 
final ArrayList< ExprambiguousAliasList_ = Lists.newArrayList()
 
SortInfo sortInfo_
 
boolean evaluateOrderBy_
 
Analyzer analyzer_
 
boolean isExplain_ = false
 

Package Functions

 SelectStmt (SelectList selectList, List< TableRef > tableRefList, Expr wherePredicate, ArrayList< Expr > groupingExprs, Expr havingPredicate, ArrayList< OrderByElement > orderByElements, LimitElement limitElement)
 

Private Member Functions

Path analyzeStarPath (List< String > rawPath, Analyzer analyzer) throws AnalysisException
 
void expandStar (Analyzer analyzer) throws AnalysisException
 
void expandStar (Path resolvedPath, Analyzer analyzer) throws AnalysisException
 
void addStarResultExpr (Path resolvedPath, Analyzer analyzer, String...relRawPath) throws AnalysisException
 
void analyzeAggregation (Analyzer analyzer) throws AnalysisException
 
ExprSubstitutionMap createCountAllMap (List< FunctionCallExpr > aggExprs, Analyzer analyzer) throws AnalysisException
 
void createAggInfo (ArrayList< Expr > groupingExprs, ArrayList< FunctionCallExpr > aggExprs, Analyzer analyzer) throws AnalysisException
 
void analyzeAnalytics (Analyzer analyzer) throws AnalysisException
 
ArrayList< TableRefcloneTableRefs ()
 

Private Attributes

Expr havingPred_
 
AggregateInfo aggInfo_
 
AnalyticInfo analyticInfo_
 
ExprSubstitutionMap baseTblSmap_ = new ExprSubstitutionMap()
 
ColumnAliasGenerator columnAliasGenerator_ = null
 
TableAliasGenerator tableAliasGenerator_ = null
 

Static Private Attributes

static final Logger LOG = LoggerFactory.getLogger(SelectStmt.class)
 

Detailed Description

Representation of a single select block, including GROUP BY, ORDER BY and HAVING clauses.

Definition at line 45 of file SelectStmt.java.

Constructor & Destructor Documentation

com.cloudera.impala.analysis.SelectStmt.SelectStmt ( SelectList  selectList,
List< TableRef tableRefList,
Expr  wherePredicate,
ArrayList< Expr groupingExprs,
Expr  havingPredicate,
ArrayList< OrderByElement orderByElements,
LimitElement  limitElement 
)
inlinepackage

Member Function Documentation

void com.cloudera.impala.analysis.SelectStmt.addStarResultExpr ( Path  resolvedPath,
Analyzer  analyzer,
String...  relRawPath 
) throws AnalysisException
inlineprivate

Helper function used during star expansion to add a single result expr based on a given raw path to be resolved relative to an existing path.

Definition at line 453 of file SelectStmt.java.

Referenced by com.cloudera.impala.analysis.SelectStmt.expandStar().

void com.cloudera.impala.analysis.SelectStmt.analyze ( Analyzer  analyzer) throws AnalysisException
inline

Creates resultExprs and baseTblResultExprs.

Implements com.cloudera.impala.analysis.ParseNode.

Definition at line 142 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.aggInfo_, com.cloudera.impala.analysis.SelectStmt.analyzeAggregation(), com.cloudera.impala.analysis.SelectStmt.analyzeAnalytics(), com.cloudera.impala.analysis.SelectStmt.analyzeStarPath(), com.cloudera.impala.analysis.SelectStmt.clone(), com.cloudera.impala.analysis.QueryStmt.createSortInfo(), com.cloudera.impala.analysis.QueryStmt.createSortTupleInfo(), com.cloudera.impala.analysis.Expr.equals(), com.cloudera.impala.analysis.QueryStmt.evaluateOrderBy_, com.cloudera.impala.analysis.SelectStmt.expandStar(), com.cloudera.impala.analysis.AggregateInfoBase.getAggregateExprs(), com.cloudera.impala.analysis.SelectListItem.getExpr(), com.cloudera.impala.analysis.SelectListItem.getRawPath(), com.cloudera.impala.analysis.QueryStmt.hasLimit(), com.cloudera.impala.analysis.Expr.isAggregatePredicate(), com.cloudera.impala.analysis.SelectList.isDistinct(), com.cloudera.impala.analysis.SelectListItem.isStar(), com.cloudera.impala.analysis.SelectStmt.resolveInlineViewRefs(), com.cloudera.impala.analysis.QueryStmt.resultExprs_, com.cloudera.impala.analysis.SelectStmt.selectList_, com.cloudera.impala.analysis.QueryStmt.sortInfo_, com.cloudera.impala.analysis.SelectStmt.sqlString_, com.cloudera.impala.analysis.SelectStmt.tableRefs_, com.cloudera.impala.analysis.SelectStmt.toSql(), and com.cloudera.impala.analysis.SelectStmt.whereClause_.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyzeAggregation().

void com.cloudera.impala.analysis.SelectStmt.analyzeAggregation ( Analyzer  analyzer) throws AnalysisException
inlineprivate

Analyze aggregation-relevant components of the select block (Group By clause, select list, Order By clause), substitute AVG with SUM/COUNT, create the AggregationInfo, including the agg output tuple, and transform all post-agg exprs given AggregationInfo's smap.

Definition at line 470 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.aggInfo_, com.cloudera.impala.analysis.QueryStmt.aliasSmap_, com.cloudera.impala.analysis.SelectStmt.analyze(), com.cloudera.impala.analysis.SelectStmt.createAggInfo(), com.cloudera.impala.analysis.SelectStmt.createCountAllMap(), com.cloudera.impala.analysis.QueryStmt.getFirstAmbiguousAlias(), com.cloudera.impala.analysis.SelectList.getItems(), com.cloudera.impala.analysis.SortInfo.getOrderingExprs(), com.cloudera.impala.analysis.AggregateInfoBase.getOutputTupleId(), com.cloudera.impala.analysis.AggregateInfo.getSecondPhaseDistinctAggInfo(), com.cloudera.impala.analysis.SelectStmt.groupingExprs_, com.cloudera.impala.analysis.SelectStmt.havingClause_, com.cloudera.impala.analysis.SelectStmt.havingPred_, com.cloudera.impala.analysis.Expr.isAggregatePredicate(), com.cloudera.impala.analysis.Expr.isBound(), com.cloudera.impala.analysis.SelectList.isDistinct(), com.cloudera.impala.analysis.QueryStmt.orderByElements_, com.cloudera.impala.analysis.QueryStmt.resultExprs_, com.cloudera.impala.analysis.SelectStmt.selectList_, com.cloudera.impala.analysis.QueryStmt.sortInfo_, com.cloudera.impala.analysis.QueryStmt.substituteOrdinals(), com.cloudera.impala.analysis.SelectStmt.tableRefs_, com.cloudera.impala.analysis.Expr.toSql(), and com.cloudera.impala.analysis.SelectStmt.toSql().

Referenced by com.cloudera.impala.analysis.SelectStmt.analyze().

void com.cloudera.impala.analysis.SelectStmt.analyzeAnalytics ( Analyzer  analyzer) throws AnalysisException
inlineprivate

If the select list contains AnalyticExprs, create AnalyticInfo and substitute AnalyticExprs using the AnalyticInfo's smap.

Definition at line 755 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.analyticInfo_, com.cloudera.impala.analysis.QueryStmt.resultExprs_, and com.cloudera.impala.analysis.QueryStmt.sortInfo_.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyze().

Path com.cloudera.impala.analysis.SelectStmt.analyzeStarPath ( List< String >  rawPath,
Analyzer  analyzer 
) throws AnalysisException
inlineprivate

Resolves the given raw path as a STAR path and checks its legality. Returns the resolved legal path, or throws if the raw path could not be resolved or is an illegal star path.

Definition at line 366 of file SelectStmt.java.

References com.cloudera.impala.analysis.Path.PathType.STAR.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyze().

ArrayList<OrderByElement> com.cloudera.impala.analysis.QueryStmt.cloneOrderByElements ( )
inlineinherited
ArrayList<TableRef> com.cloudera.impala.analysis.SelectStmt.cloneTableRefs ( )
inlineprivate
void com.cloudera.impala.analysis.SelectStmt.createAggInfo ( ArrayList< Expr groupingExprs,
ArrayList< FunctionCallExpr aggExprs,
Analyzer  analyzer 
) throws AnalysisException
inlineprivate
ExprSubstitutionMap com.cloudera.impala.analysis.SelectStmt.createCountAllMap ( List< FunctionCallExpr aggExprs,
Analyzer  analyzer 
) throws AnalysisException
inlineprivate

Create a map from COUNT([ALL]) -> zeroifnull(COUNT([ALL])) if i) There is no GROUP-BY, and ii) There are other distinct aggregates to be evaluated. This transformation is necessary for COUNT to correctly return 0 for empty input relations.

Definition at line 689 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.groupingExprs_.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyzeAggregation().

void com.cloudera.impala.analysis.QueryStmt.createSortInfo ( Analyzer  analyzer) throws AnalysisException
inlineprotectedinherited

Creates sortInfo by resolving aliases and ordinals in the orderingExprs. If the query stmt is an inline view/union operand, then order-by with no limit with offset is not allowed, since that requires a sort and merging-exchange, and subsequent query execution would occur on a single machine. Sets evaluateOrderBy_ to false for ignored order-by w/o limit/offset in nested queries.

Definition at line 115 of file QueryStmt.java.

References com.cloudera.impala.analysis.QueryStmt.aliasSmap_, com.cloudera.impala.analysis.QueryStmt.clone(), com.cloudera.impala.analysis.QueryStmt.evaluateOrderBy_, com.cloudera.impala.analysis.QueryStmt.getFirstAmbiguousAlias(), com.cloudera.impala.analysis.QueryStmt.hasLimit(), com.cloudera.impala.analysis.QueryStmt.hasOffset(), com.cloudera.impala.analysis.QueryStmt.orderByElements_, com.cloudera.impala.analysis.QueryStmt.sortInfo_, com.cloudera.impala.analysis.QueryStmt.substituteOrdinals(), com.cloudera.impala.analysis.StatementBase.toSql(), and com.cloudera.impala.analysis.Expr.toSql().

Referenced by com.cloudera.impala.analysis.SelectStmt.analyze(), and com.cloudera.impala.analysis.UnionStmt.analyze().

void com.cloudera.impala.analysis.QueryStmt.createSortTupleInfo ( Analyzer  analyzer)
inlineprotectedinherited

Create a tuple descriptor for the single tuple that is materialized, sorted and output by the exec node implementing the sort. Done by materializing slot refs in the order-by and result expressions. Those SlotRefs in the ordering and result exprs are substituted with SlotRefs into the new tuple. This simplifies sorting logic for total (no limit) sorts. Done after analyzeAggregation() since ordering and result exprs may refer to the outputs of aggregation. Invoked for UnionStmt as well since TODO: We could do something more sophisticated than simply copying input slotrefs - e.g. compute some order-by expressions.

Definition at line 185 of file QueryStmt.java.

References com.cloudera.impala.analysis.QueryStmt.evaluateOrderBy_, and com.cloudera.impala.analysis.QueryStmt.resultExprs_.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyze(), and com.cloudera.impala.analysis.UnionStmt.analyze().

boolean com.cloudera.impala.analysis.QueryStmt.evaluateOrderBy ( )
inlineinherited
void com.cloudera.impala.analysis.SelectStmt.expandStar ( Analyzer  analyzer) throws AnalysisException
inlineprivate

Expand "*" select list item, ignoring semi-joined tables.

Definition at line 382 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.tableRefs_.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyze().

AggregateInfo com.cloudera.impala.analysis.SelectStmt.getAggInfo ( )
inline

Definition at line 112 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.aggInfo_.

AnalyticInfo com.cloudera.impala.analysis.SelectStmt.getAnalyticInfo ( )
inline
Analyzer com.cloudera.impala.analysis.QueryStmt.getAnalyzer ( )
inlineinherited
ExprSubstitutionMap com.cloudera.impala.analysis.SelectStmt.getBaseTblSmap ( )
inline
ArrayList<String> com.cloudera.impala.analysis.SelectStmt.getColLabels ( )
inline
ColumnAliasGenerator com.cloudera.impala.analysis.SelectStmt.getColumnAliasGenerator ( )
inline
Expr com.cloudera.impala.analysis.QueryStmt.getFirstAmbiguousAlias ( List< Expr exprs)
inlineprotectedinherited

Return the first expr in exprs that is a non-unique alias. Return null if none of exprs is an ambiguous alias.

Definition at line 219 of file QueryStmt.java.

References com.cloudera.impala.analysis.QueryStmt.ambiguousAliasList_.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyzeAggregation(), and com.cloudera.impala.analysis.QueryStmt.createSortInfo().

Expr com.cloudera.impala.analysis.SelectStmt.getHavingPred ( )
inline
Returns
the HAVING clause post-analysis and with aliases resolved

Definition at line 105 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.havingPred_.

Referenced by com.cloudera.impala.analysis.AnalyzerTest.checkSelectToThrift().

long com.cloudera.impala.analysis.QueryStmt.getLimit ( )
inlineinherited

Definition at line 274 of file QueryStmt.java.

Referenced by com.cloudera.impala.analysis.QueryStmt.setLimit().

void com.cloudera.impala.analysis.SelectStmt.getMaterializedTupleIds ( ArrayList< TupleId tupleIdList)
inline

If the select statement has a sort/top that is evaluated, then the sort tuple is materialized. Else, if there is aggregation then the aggregate tuple id is materialized. Otherwise, all referenced tables are materialized as long as they are not semi-joined. If there are analytics and no sort, then the returned tuple ids also include the logical analytic output tuple.

Definition at line 851 of file SelectStmt.java.

References com.cloudera.impala.analysis.SelectStmt.aggInfo_, com.cloudera.impala.analysis.QueryStmt.evaluateOrderBy_, com.cloudera.impala.analysis.SelectStmt.hasAnalyticInfo(), and com.cloudera.impala.analysis.SelectStmt.tableRefs_.

Referenced by com.cloudera.impala.analysis.SelectStmt.materializeRequiredSlots().

long com.cloudera.impala.analysis.QueryStmt.getOffset ( )
inlineinherited

Definition at line 276 of file QueryStmt.java.

SelectList com.cloudera.impala.analysis.SelectStmt.getSelectList ( )
inline
SortInfo com.cloudera.impala.analysis.QueryStmt.getSortInfo ( )
inlineinherited

Definition at line 277 of file QueryStmt.java.

References com.cloudera.impala.analysis.QueryStmt.sortInfo_.

TableAliasGenerator com.cloudera.impala.analysis.SelectStmt.getTableAliasGenerator ( )
inline
List<TupleId> com.cloudera.impala.analysis.SelectStmt.getTableRefIds ( )
inline
Expr com.cloudera.impala.analysis.SelectStmt.getWhereClause ( )
inline
WithClause com.cloudera.impala.analysis.QueryStmt.getWithClause ( )
inlineinherited
boolean com.cloudera.impala.analysis.SelectStmt.hasAggInfo ( )
inline
boolean com.cloudera.impala.analysis.SelectStmt.hasAnalyticInfo ( )
inline
boolean com.cloudera.impala.analysis.QueryStmt.hasOffset ( )
inlineinherited
boolean com.cloudera.impala.analysis.QueryStmt.hasOrderByClause ( )
inlineinherited
boolean com.cloudera.impala.analysis.SelectStmt.hasWhereClause ( )
inline
boolean com.cloudera.impala.analysis.QueryStmt.hasWithClause ( )
inlineinherited
boolean com.cloudera.impala.analysis.StatementBase.isExplain ( )
inlineinherited
void com.cloudera.impala.analysis.QueryStmt.materializeSlots ( Analyzer  analyzer,
List< Expr exprs 
)
inlineprotectedinherited

Mark slots referenced in exprs as materialized.

Definition at line 303 of file QueryStmt.java.

Referenced by com.cloudera.impala.analysis.UnionStmt.materializeRequiredSlots(), and com.cloudera.impala.analysis.SelectStmt.materializeRequiredSlots().

void com.cloudera.impala.analysis.SelectStmt.resolveInlineViewRefs ( Analyzer  analyzer) throws AnalysisException
inlineprotected
boolean com.cloudera.impala.analysis.SelectStmt.returnsSingleRow ( )
inline

Check if the stmt returns a single row. This can happen in the following cases:

  1. select stmt with a 'limit 1' clause
  2. select stmt with an aggregate function and no group by.
  3. select stmt with no from clause.

This function may produce false negatives because the cardinality of the result set also depends on the data a stmt is processing.

Definition at line 904 of file SelectStmt.java.

References com.cloudera.impala.analysis.LimitElement.getLimit(), com.cloudera.impala.analysis.SelectStmt.hasAggInfo(), com.cloudera.impala.analysis.SelectStmt.hasGroupByClause(), com.cloudera.impala.analysis.QueryStmt.limitElement_, and com.cloudera.impala.analysis.SelectStmt.tableRefs_.

void com.cloudera.impala.analysis.StatementBase.setIsExplain ( )
inlineinherited
void com.cloudera.impala.analysis.SelectStmt.setWhereClause ( Expr  whereClause)
inline
void com.cloudera.impala.analysis.QueryStmt.setWithClause ( WithClause  withClause)
inlineinherited

Definition at line 269 of file QueryStmt.java.

void com.cloudera.impala.analysis.QueryStmt.substituteOrdinals ( List< Expr exprs,
String  errorPrefix,
Analyzer  analyzer 
) throws AnalysisException
inlineprotectedinherited

Member Data Documentation

final ExprSubstitutionMap com.cloudera.impala.analysis.QueryStmt.aliasSmap_ = new ExprSubstitutionMap()
protectedinherited

Map of expression substitutions for replacing aliases in "order by" or "group by" clauses with their corresponding result expr.

Definition at line 62 of file QueryStmt.java.

Referenced by com.cloudera.impala.analysis.SelectStmt.analyzeAggregation(), com.cloudera.impala.analysis.UnionStmt.createMetadata(), and com.cloudera.impala.analysis.QueryStmt.createSortInfo().

final ArrayList<Expr> com.cloudera.impala.analysis.QueryStmt.ambiguousAliasList_ = Lists.newArrayList()
protectedinherited

Select list item alias does not have to be unique. This list contains all the non-unique aliases. For example, select int_col a, string_col a from alltypessmall; Both columns are using the same alias "a".

Definition at line 70 of file QueryStmt.java.

Referenced by com.cloudera.impala.analysis.QueryStmt.getFirstAmbiguousAlias().

Analyzer com.cloudera.impala.analysis.QueryStmt.analyzer_
protectedinherited
ArrayList<Expr> com.cloudera.impala.analysis.QueryStmt.baseTblResultExprs_ = Lists.newArrayList()
protectedinherited
final ArrayList<String> com.cloudera.impala.analysis.SelectStmt.colLabels_
protected
ColumnAliasGenerator com.cloudera.impala.analysis.SelectStmt.columnAliasGenerator_ = null
private
final Expr com.cloudera.impala.analysis.SelectStmt.havingClause_
protected
final Logger com.cloudera.impala.analysis.SelectStmt.LOG = LoggerFactory.getLogger(SelectStmt.class)
staticprivate

Definition at line 46 of file SelectStmt.java.

String com.cloudera.impala.analysis.SelectStmt.sqlString_
protected
TableAliasGenerator com.cloudera.impala.analysis.SelectStmt.tableAliasGenerator_ = null
private

The documentation for this class was generated from the following file: