OmniSciDB  72c90bc290
 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 6118 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 6132 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.

6132  {
6133  if (id.isSimple() && getScope() instanceof GroupByScope) { // HEAVY.AI new
6134  RelDataType dataType = getScope().resolveColumn(id.names.get(0), id); // HEAVY.AI new
6135  // Ensure that column names take precedence over aliases in // HEAVY.AI new
6136  // GROUP BY clauses. // HEAVY.AI new
6137  if (dataType != null) { // HEAVY.AI new
6138  return super.visit(id); // HEAVY.AI new
6139  } // HEAVY.AI new
6140  } // HEAVY.AI new
6141  if (id.isSimple()
6142  && (havingExpr
6143  ? validator.config().sqlConformance().isHavingAlias()
6144  : validator.config().sqlConformance().isGroupByAlias())) {
6145  String name = id.getSimple();
6146  SqlNode expr = null;
6147  final SqlNameMatcher nameMatcher =
6148  validator.catalogReader.nameMatcher();
6149  int n = 0;
6150  for (SqlNode s : select.getSelectList()) {
6151  final String alias = SqlValidatorUtil.getAlias(s, -1);
6152  if (alias != null && nameMatcher.matches(alias, name)) {
6153  expr = s;
6154  n++;
6155  }
6156  }
6157  if (n == 0) {
6158  return super.visit(id);
6159  } else if (n > 1) {
6160  // More than one column has this alias.
6161  throw validator.newValidationError(id,
6162  RESOURCE.columnAmbiguous(name));
6163  }
6165  return super.visit(id);
6166  }
6167  expr = stripAs(expr);
6168  if (expr instanceof SqlIdentifier) {
6169  SqlIdentifier sid = (SqlIdentifier) expr;
6170  final SqlIdentifier fqId = getScope().fullyQualify(sid).identifier;
6171  expr = expandDynamicStar(sid, fqId);
6172 
6173  } else { // HEAVY.AI new
6174  // The selectList item has not yet been expanded, // HEAVY.AI new
6175  // so it may need to be expanded *once* more to deal // HEAVY.AI new
6176  // with default arguments to a UDF that are provided // HEAVY.AI new
6177  // when the SqlCall is created. Trigger that process // HEAVY.AI new
6178  // by expanding once more, but *only* on the initial // HEAVY.AI new
6179  // alias replacement // HEAVY.AI new
6180  // HEAVY.AI new
6181  if(!bNested){ // HEAVY.AI new
6182  bNested = true; // HEAVY.AI new
6183  expr = expr.accept(this); // HEAVY.AI new
6184  bNested = false;; // HEAVY.AI new
6185  } // HEAVY.AI new
6186 
6187  }
6188  return expr;
6189  }
6190  if (id.isSimple()) {
6191  final SelectScope scope = validator.getRawSelectScope(select);
6192  SqlNode node = expandCommonColumn(select, id, scope, validator);
6193  if (node != id) {
6194  return node;
6195  }
6196  }
6197  return super.visit(id);
6198  }
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 6200 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.

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

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: