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

Classes

enum  Qualifier
 
class  UnionOperand
 

Public Member Functions

 UnionStmt (List< UnionOperand > operands, ArrayList< OrderByElement > orderByElements, LimitElement limitElement)
 
List< UnionOperandgetOperands ()
 
List< UnionOperandgetDistinctOperands ()
 
boolean hasDistinctOps ()
 
List< UnionOperandgetAllOperands ()
 
boolean hasAllOps ()
 
AggregateInfo getDistinctAggInfo ()
 
boolean hasAnalyticExprs ()
 
void removeAllOperands ()
 
void analyze (Analyzer analyzer) throws AnalysisException
 
void materializeRequiredSlots (Analyzer analyzer) throws InternalException
 
TupleId getTupleId ()
 
void getMaterializedTupleIds (ArrayList< TupleId > tupleIdList)
 
String toSql ()
 
ArrayList< String > getColLabels ()
 
QueryStmt clone ()
 
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

String queryStmtToSql (QueryStmt queryStmt)
 
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

final List< UnionOperandoperands_
 
final List< UnionOperanddistinctOperands_ = Lists.newArrayList()
 
final List< UnionOperandallOperands_ = Lists.newArrayList()
 
AggregateInfo distinctAggInfo_
 
TupleId tupleId_
 
String toSqlString_ = null
 
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
 

Private Member Functions

void unnestOperands (Analyzer analyzer) throws AnalysisException
 
void setOperandSmap (UnionOperand operand, Analyzer analyzer)
 
void unnestOperand (List< UnionOperand > target, Qualifier targetQualifier, UnionOperand operand)
 
void propagateDistinct ()
 
void createMetadata (Analyzer analyzer) throws AnalysisException
 

Private Attributes

boolean hasAnalyticExprs_ = false
 

Static Private Attributes

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

Detailed Description

Representation of a union with its list of operands, and optional order by and limit. A union materializes its results, and its resultExprs are slotrefs into the materialized tuple. During analysis, the operands are normalized (separated into a single sequence of DISTINCT followed by a single sequence of ALL operands) and unnested to the extent possible. This also creates the AggregationInfo for DISTINCT operands.

Definition at line 37 of file UnionStmt.java.

Constructor & Destructor Documentation

com.cloudera.impala.analysis.UnionStmt.UnionStmt ( List< UnionOperand operands,
ArrayList< OrderByElement orderByElements,
LimitElement  limitElement 
)
inline

Member Function Documentation

ArrayList<OrderByElement> com.cloudera.impala.analysis.QueryStmt.cloneOrderByElements ( )
inlineinherited
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
List<UnionOperand> com.cloudera.impala.analysis.UnionStmt.getAllOperands ( )
inline
Analyzer com.cloudera.impala.analysis.QueryStmt.getAnalyzer ( )
inlineinherited
ArrayList<String> com.cloudera.impala.analysis.UnionStmt.getColLabels ( )
inline
AggregateInfo com.cloudera.impala.analysis.UnionStmt.getDistinctAggInfo ( )
inline
List<UnionOperand> com.cloudera.impala.analysis.UnionStmt.getDistinctOperands ( )
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().

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.UnionStmt.getMaterializedTupleIds ( ArrayList< TupleId tupleIdList)
inline
long com.cloudera.impala.analysis.QueryStmt.getOffset ( )
inlineinherited

Definition at line 276 of file QueryStmt.java.

List<UnionOperand> com.cloudera.impala.analysis.UnionStmt.getOperands ( )
inline

Definition at line 131 of file UnionStmt.java.

References com.cloudera.impala.analysis.UnionStmt.operands_.

SortInfo com.cloudera.impala.analysis.QueryStmt.getSortInfo ( )
inlineinherited

Definition at line 277 of file QueryStmt.java.

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

TupleId com.cloudera.impala.analysis.UnionStmt.getTupleId ( )
inline

Definition at line 459 of file UnionStmt.java.

References com.cloudera.impala.analysis.UnionStmt.tupleId_.

WithClause com.cloudera.impala.analysis.QueryStmt.getWithClause ( )
inlineinherited
boolean com.cloudera.impala.analysis.UnionStmt.hasAllOps ( )
inline

Definition at line 135 of file UnionStmt.java.

boolean com.cloudera.impala.analysis.UnionStmt.hasAnalyticExprs ( )
inline
boolean com.cloudera.impala.analysis.UnionStmt.hasDistinctOps ( )
inline

Definition at line 133 of file UnionStmt.java.

boolean com.cloudera.impala.analysis.QueryStmt.hasOffset ( )
inlineinherited
boolean com.cloudera.impala.analysis.QueryStmt.hasOrderByClause ( )
inlineinherited
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.UnionStmt.propagateDistinct ( )
inlineprivate

Propagates DISTINCT (if present) from right to left. Implied associativity: A UNION ALL B UNION DISTINCT C = (A UNION ALL B) UNION DISTINCT C = A UNION DISTINCT B UNION DISTINCT C

Definition at line 380 of file UnionStmt.java.

References com.cloudera.impala.analysis.UnionStmt.Qualifier.DISTINCT, com.cloudera.impala.analysis.UnionStmt.UnionOperand.getQualifier(), and com.cloudera.impala.analysis.UnionStmt.operands_.

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

String com.cloudera.impala.analysis.UnionStmt.queryStmtToSql ( QueryStmt  queryStmt)
inlineprotected

String representation of queryStmt used in reporting errors. Allow subclasses to override this.

Definition at line 370 of file UnionStmt.java.

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

void com.cloudera.impala.analysis.UnionStmt.removeAllOperands ( )
inline
void com.cloudera.impala.analysis.StatementBase.setIsExplain ( )
inlineinherited
void com.cloudera.impala.analysis.UnionStmt.setOperandSmap ( UnionOperand  operand,
Analyzer  analyzer 
)
inlineprivate

Sets the smap for the given operand. It maps from the output slots this union's tuple to the corresponding base table exprs of the operand.

Definition at line 322 of file UnionStmt.java.

References com.cloudera.impala.analysis.UnionStmt.clone(), com.cloudera.impala.analysis.QueryStmt.getResultExprs(), and com.cloudera.impala.analysis.UnionStmt.tupleId_.

Referenced by com.cloudera.impala.analysis.UnionStmt.unnestOperands().

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
void com.cloudera.impala.analysis.UnionStmt.unnestOperand ( List< UnionOperand target,
Qualifier  targetQualifier,
UnionOperand  operand 
)
inlineprivate

Add a single operand to the target list; if the operand itself is a UnionStmt, apply unnesting to the extent possible (possibly modifying 'operand' in the process).

Definition at line 339 of file UnionStmt.java.

References com.cloudera.impala.analysis.UnionStmt.Qualifier.DISTINCT, and com.cloudera.impala.analysis.UnionStmt.UnionStmt().

Referenced by com.cloudera.impala.analysis.UnionStmt.unnestOperands().

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 List<UnionOperand> com.cloudera.impala.analysis.UnionStmt.allOperands_ = Lists.newArrayList()
protected
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 List<UnionOperand> com.cloudera.impala.analysis.UnionStmt.distinctOperands_ = Lists.newArrayList()
protected
boolean com.cloudera.impala.analysis.UnionStmt.hasAnalyticExprs_ = false
private
final Logger com.cloudera.impala.analysis.UnionStmt.LOG = LoggerFactory.getLogger(UnionStmt.class)
staticprivate

Definition at line 38 of file UnionStmt.java.

String com.cloudera.impala.analysis.UnionStmt.toSqlString_ = null
protected

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