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

Public Member Functions

SqlNode visit (SqlIdentifier id)
 
SqlNode visit (SqlLiteral literal)
 
- Public Member Functions inherited from org.apache.calcite.sql.validate.SqlValidatorImpl.Expander
SqlNode visit (SqlIdentifier id)
 

Package Functions

 ExtendedExpander (SqlValidatorImpl validator, SqlValidatorScope scope, SqlSelect select, SqlNode root, boolean havingExpr)
 
- Package Functions inherited from org.apache.calcite.sql.validate.SqlValidatorImpl.Expander
 Expander (SqlValidatorImpl validator, SqlValidatorScope scope)
 

Package Attributes

final SqlSelect select
 
final SqlNode root
 
final boolean havingExpr
 
boolean bNested = false
 

Additional Inherited Members

- Protected Member Functions inherited from org.apache.calcite.sql.validate.SqlValidatorImpl.Expander
SqlNode visitScoped (SqlCall call)
 
SqlNode expandDynamicStar (SqlIdentifier id, SqlIdentifier fqId)
 
- Protected Attributes inherited from org.apache.calcite.sql.validate.SqlValidatorImpl.Expander
final SqlValidatorImpl validator
 

Detailed Description

Shuttle which walks over an expression in the GROUP BY/HAVING clause, replacing usages of aliases or ordinals with the underlying expression.

Definition at line 6115 of file SqlValidatorImpl.java.

Constructor & Destructor Documentation

org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.ExtendedExpander ( SqlValidatorImpl  validator,
SqlValidatorScope  scope,
SqlSelect  select,
SqlNode  root,
boolean  havingExpr 
)
inlinepackage

Member Function Documentation

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

Definition at line 6129 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.bNested, org.apache.calcite.sql.validate.SqlValidatorImpl.config, org.apache.calcite.sql.validate.SqlValidatorImpl.expandCommonColumn(), org.apache.calcite.sql.validate.SqlValidatorImpl.Expander.expandDynamicStar(), org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.havingExpr, org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate(), anonymous_namespace{Utm.h}.n, setup.name, org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.root, org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.select, and org.apache.calcite.sql.validate.SqlValidatorImpl.Expander.validator.

6129  {
6130  if (id.isSimple()
6131  && (havingExpr
6132  ? validator.config().sqlConformance().isHavingAlias()
6133  : validator.config().sqlConformance().isGroupByAlias())) {
6134  String name = id.getSimple();
6135  SqlNode expr = null;
6136  final SqlNameMatcher nameMatcher =
6137  validator.catalogReader.nameMatcher();
6138  int n = 0;
6139  for (SqlNode s : select.getSelectList()) {
6140  final String alias = SqlValidatorUtil.getAlias(s, -1);
6141  if (alias != null && nameMatcher.matches(alias, name)) {
6142  expr = s;
6143  n++;
6144  }
6145  }
6146  if (n == 0) {
6147  return super.visit(id);
6148  } else if (n > 1) {
6149  // More than one column has this alias.
6150  throw validator.newValidationError(id,
6151  RESOURCE.columnAmbiguous(name));
6152  }
6154  return super.visit(id);
6155  }
6156  expr = stripAs(expr);
6157  if (expr instanceof SqlIdentifier) {
6158  SqlIdentifier sid = (SqlIdentifier) expr;
6159  final SqlIdentifier fqId = getScope().fullyQualify(sid).identifier;
6160  expr = expandDynamicStar(sid, fqId);
6161 
6162  } else { // HEAVY.AI new
6163  // The selectList item has not yet been expanded, // HEAVY.AI new
6164  // so it may need to be expanded *once* more to deal // HEAVY.AI new
6165  // with default arguments to a UDF that are provided // HEAVY.AI new
6166  // when the SqlCall is created. Trigger that process // HEAVY.AI new
6167  // by expanding once more, but *only* on the initial // HEAVY.AI new
6168  // alias replacement // HEAVY.AI new
6169  // HEAVY.AI new
6170  if(!bNested){ // HEAVY.AI new
6171  bNested = true; // HEAVY.AI new
6172  expr = expr.accept(this); // HEAVY.AI new
6173  bNested = false;; // HEAVY.AI new
6174  } // HEAVY.AI new
6175 
6176  }
6177  return expr;
6178  }
6179  if (id.isSimple()) {
6180  final SelectScope scope = validator.getRawSelectScope(select);
6181  SqlNode node = expandCommonColumn(select, id, scope, validator);
6182  if (node != id) {
6183  return node;
6184  }
6185  }
6186  return super.visit(id);
6187  }
SqlNode expandDynamicStar(SqlIdentifier id, SqlIdentifier fqId)
static SqlNode expandCommonColumn(SqlSelect sqlSelect, SqlNode selectItem, SelectScope scope, SqlValidatorImpl validator)
string name
Definition: setup.in.py:72
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

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

Definition at line 6189 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.bNested, org.apache.calcite.sql.validate.SqlValidatorImpl.config, org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.havingExpr, org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.root, org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.select, and org.apache.calcite.sql.validate.SqlValidatorImpl.Expander.validator.

6189  {
6190  if (havingExpr || !validator.config().sqlConformance().isGroupByOrdinal()) {
6191  return super.visit(literal);
6192  }
6193  boolean isOrdinalLiteral = literal == root;
6194  switch (root.getKind()) {
6195  case GROUPING_SETS:
6196  case ROLLUP:
6197  case CUBE:
6198  if (root instanceof SqlBasicCall) {
6199  List<SqlNode> operandList = ((SqlBasicCall) root).getOperandList();
6200  for (SqlNode node : operandList) {
6201  if (node.equals(literal)) {
6202  isOrdinalLiteral = true;
6203  break;
6204  }
6205  }
6206  }
6207  break;
6208  }
6209  if (isOrdinalLiteral) {
6210  switch (literal.getTypeName()) {
6211  case DECIMAL:
6212  case DOUBLE:
6213  final int intValue = literal.intValue(false);
6214  if (intValue >= 0) {
6215  if (intValue < 1 || intValue > select.getSelectList().size()) {
6216  throw validator.newValidationError(literal,
6217  RESOURCE.orderByOrdinalOutOfRange());
6218  }
6219 
6220  // SQL ordinals are 1-based, but Sort's are 0-based
6221  int ordinal = intValue - 1;
6222 
6223  // return SqlUtil.stripAs(select.getSelectList().get(ordinal)); // HEAVY.AI original
6224 
6225  // The selectList item has not yet been expanded, so it may need to be // HEAVY.AI new
6226  // expanded *once* to deal with default arguments to a UDF that are // HEAVY.AI new
6227  // provided when the SqlCall is created. Trigger that process by // HEAVY.AI new
6228  // expanding once more, but *only* on the initial literal replacement // HEAVY.AI new
6229  // HEAVY.AI new
6230  SqlNode node = SqlUtil.stripAs(select.getSelectList().get(ordinal)); // HEAVY.AI new
6231  // HEAVY.AI new
6232  if(!bNested){ // HEAVY.AI new
6233  bNested = true; // HEAVY.AI new
6234  node = node.accept(this); // HEAVY.AI new
6235  bNested = false; // HEAVY.AI new
6236  } // HEAVY.AI new
6237  return node; // HEAVY.AI new
6238 
6239  }
6240  break;
6241  }
6242  }
6243 
6244  return super.visit(literal);
6245  }

Member Data Documentation

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.bNested = false
package
final boolean org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.havingExpr
package
final SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.root
package
final SqlSelect org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.select
package

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