OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander Class Reference
+ Inheritance diagram for org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander:
+ Collaboration diagram for org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander:

Public Member Functions

SqlNode go ()
 
SqlNode visit (SqlLiteral literal)
 
SqlNode visit (SqlIdentifier id)
 

Protected Member Functions

SqlNode visitScoped (SqlCall call)
 

Package Functions

 OrderExpressionExpander (SqlSelect select, SqlNode root)
 

Private Member Functions

SqlNode nthSelectItem (int ordinal, final SqlParserPos pos)
 

Private Attributes

final List< String > aliasList
 
final SqlSelect select
 
final SqlNode root
 

Detailed Description

Shuttle which walks over an expression in the ORDER BY clause, replacing usages of aliases with the underlying expression.

Definition at line 5990 of file SqlValidatorImpl.java.

Constructor & Destructor Documentation

org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.OrderExpressionExpander ( SqlSelect  select,
SqlNode  root 
)
inlinepackage

Definition at line 5995 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.getOrderScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.root, and org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.select.

5995  {
5996  super(getOrderScope(select));
5997  this.select = select;
5998  this.root = root;
5999  this.aliasList = getNamespace(select).getRowType().getFieldNames();
6000  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
SqlValidatorScope getOrderScope(SqlSelect select)

+ Here is the call graph for this function:

Member Function Documentation

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.go ( )
inline

Definition at line 6002 of file SqlValidatorImpl.java.

6002  {
6003  return root.accept(this);
6004  }
SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.nthSelectItem ( int  ordinal,
final SqlParserPos  pos 
)
inlineprivate

Returns the ordinalth item in the select list.

Definition at line 6035 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), and org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.select.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.visit().

6035  {
6036  // TODO: Don't expand the list every time. Maybe keep an expanded
6037  // version of each expression -- select lists and identifiers -- in
6038  // the validator.
6039 
6040  SqlNodeList expandedSelectList =
6041  expandStar(
6042  select.getSelectList(),
6043  select,
6044  false);
6045  SqlNode expr = expandedSelectList.get(ordinal);
6046  expr = stripAs(expr);
6047  if (expr instanceof SqlIdentifier) {
6048  expr = getScope().fullyQualify((SqlIdentifier) expr).identifier;
6049  }
6050 
6051  // Create a copy of the expression with the position of the order
6052  // item.
6053  return expr.clone(pos);
6054  }
SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.visit ( SqlLiteral  literal)
inline

Definition at line 6006 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.aliasList, org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.nthSelectItem(), and org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.root.

6006  {
6007  // Ordinal markers, e.g. 'select a, b from t order by 2'.
6008  // Only recognize them if they are the whole expression,
6009  // and if the dialect permits.
6010  if (literal == root && config.sqlConformance().isSortByOrdinal()) {
6011  switch (literal.getTypeName()) {
6012  case DECIMAL:
6013  case DOUBLE:
6014  final int intValue = literal.intValue(false);
6015  if (intValue >= 0) {
6016  if (intValue < 1 || intValue > aliasList.size()) {
6017  throw newValidationError(
6018  literal, RESOURCE.orderByOrdinalOutOfRange());
6019  }
6020 
6021  // SQL ordinals are 1-based, but Sort's are 0-based
6022  int ordinal = intValue - 1;
6023  return nthSelectItem(ordinal, literal.getParserPosition());
6024  }
6025  break;
6026  }
6027  }
6028 
6029  return super.visit(literal);
6030  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)

+ Here is the call graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.visit ( SqlIdentifier  id)
inline

Definition at line 6056 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.config(), field(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.nthSelectItem(), and org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.select.

6056  {
6057  // Aliases, e.g. 'select a as x, b from t order by x'.
6058  if (id.isSimple()
6059  && config.sqlConformance().isSortByAlias()) {
6060  String alias = id.getSimple();
6061  final SqlValidatorNamespace selectNs = getNamespace(select);
6062  final RelDataType rowType =
6063  selectNs.getRowTypeSansSystemColumns();
6064  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
6065  RelDataTypeField field = nameMatcher.field(rowType, alias);
6066  if (field != null) {
6067  return nthSelectItem(
6068  field.getIndex(),
6069  id.getParserPosition());
6070  }
6071  }
6072 
6073  // No match. Return identifier unchanged.
6074  return getScope().fullyQualify(id).identifier;
6075  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31

+ Here is the call graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.visitScoped ( SqlCall  call)
inlineprotected

Definition at line 6077 of file SqlValidatorImpl.java.

6077  {
6078  // Don't attempt to expand sub-queries. We haven't implemented
6079  // these yet.
6080  if (call instanceof SqlSelect) {
6081  return call;
6082  }
6083  return super.visitScoped(call);
6084  }

Member Data Documentation

final List<String> org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.aliasList
private
final SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.root
private

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