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

Classes

enum  Clause
 
class  DeleteNamespace
 
class  DeriveTypeVisitor
 
class  DmlNamespace
 
class  Expander
 
class  ExtendedExpander
 
class  FunctionParamInfo
 
class  IdInfo
 
class  InsertNamespace
 
class  MergeNamespace
 
class  NavigationExpander
 
class  NavigationModifier
 
class  NavigationReplacer
 
class  OrderExpressionExpander
 
class  PatternValidator
 
class  PatternVarVisitor
 
class  Permute
 
class  SelectExpander
 
enum  Status
 
class  UpdateNamespace
 
class  ValidationError
 
class  ValidationErrorFunction
 

Public Member Functions

SqlConformance getConformance ()
 
SqlValidatorCatalogReader getCatalogReader ()
 
SqlOperatorTable getOperatorTable ()
 
RelDataTypeFactory getTypeFactory ()
 
RelDataType getUnknownType ()
 
SqlNodeList expandStar (SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
 
void declareCursor (SqlSelect select, SqlValidatorScope parentScope)
 
void pushFunctionCall ()
 
void popFunctionCall ()
 
String getParentCursor (String columnListParamName)
 
List< String > usingNames (SqlJoin join)
 
SqlNode validate (SqlNode topNode)
 
List< SqlMoniker > lookupHints (SqlNode topNode, SqlParserPos pos)
 
SqlMoniker lookupQualifiedName (SqlNode topNode, SqlParserPos pos)
 
final void lookupNameCompletionHints (SqlValidatorScope scope, List< String > names, SqlParserPos pos, Collection< SqlMoniker > hintList)
 
SqlNode validateParameterizedExpression (SqlNode topNode, final Map< String, RelDataType > nameToTypeMap)
 
void validateQuery (SqlNode node, SqlValidatorScope scope, RelDataType targetRowType)
 
SqlValidatorScope getEmptyScope ()
 
SqlValidatorScope getCursorScope (SqlSelect select)
 
SqlValidatorScope getWhereScope (SqlSelect select)
 
SqlValidatorScope getSelectScope (SqlSelect select)
 
SelectScope getRawSelectScope (SqlSelect select)
 
SqlValidatorScope getHavingScope (SqlSelect select)
 
SqlValidatorScope getGroupScope (SqlSelect select)
 
SqlValidatorScope getFromScope (SqlSelect select)
 
SqlValidatorScope getOrderScope (SqlSelect select)
 
SqlValidatorScope getMatchRecognizeScope (SqlMatchRecognize node)
 
SqlValidatorScope getJoinScope (SqlNode node)
 
SqlValidatorScope getOverScope (SqlNode node)
 
SqlValidatorNamespace getNamespace (SqlNode node)
 
RelDataType getValidatedNodeType (SqlNode node)
 
RelDataType getValidatedNodeTypeIfKnown (SqlNode node)
 
final void setValidatedNodeType (SqlNode node, RelDataType type)
 
void removeValidatedNodeType (SqlNode node)
 
SqlCall makeNullaryCall (SqlIdentifier id)
 
RelDataType deriveType (SqlValidatorScope scope, SqlNode expr)
 
RelDataType deriveConstructorType (SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, SqlFunction resolvedConstructor, List< RelDataType > argTypes)
 
CalciteException handleUnresolvedFunction (SqlCall call, SqlFunction unresolvedFunction, List< RelDataType > argTypes, List< String > argNames)
 
String deriveAlias (SqlNode node, int ordinal)
 
boolean isAggregate (SqlSelect select)
 
boolean isAggregate (SqlNode selectNode)
 
void validateIdentifier (SqlIdentifier id, SqlValidatorScope scope)
 
void validateLiteral (SqlLiteral literal)
 
void validateIntervalQualifier (SqlIntervalQualifier qualifier)
 
boolean validateModality (SqlSelect select, SqlModality modality, boolean fail)
 
void validateWith (SqlWith with, SqlValidatorScope scope)
 
void validateWithItem (SqlWithItem withItem)
 
void validateSequenceValue (SqlValidatorScope scope, SqlIdentifier id)
 
SqlValidatorScope getWithScope (SqlNode withItem)
 
TypeCoercion getTypeCoercion ()
 
Config config ()
 
SqlValidator transform (UnaryOperator< Config > transform)
 
SqlNode expandOrderExpr (SqlSelect select, SqlNode orderExpr)
 
void validateInsert (SqlInsert insert)
 
void validateDelete (SqlDelete call)
 
void validateUpdate (SqlUpdate call)
 
void validateMerge (SqlMerge call)
 
void validateDataType (SqlDataTypeSpec dataType)
 
void validateDynamicParam (SqlDynamicParam dynamicParam)
 
ValidationErrorFunction getValidationErrorFunction ()
 
CalciteContextException newValidationError (SqlNode node, Resources.ExInst< SqlValidatorException > e)
 
SqlWindow resolveWindow (SqlNode windowOrRef, SqlValidatorScope scope)
 
SqlNode getOriginal (SqlNode expr)
 
void setOriginal (SqlNode expr, SqlNode original)
 
void validateWindow (SqlNode windowOrId, SqlValidatorScope scope, SqlCall call)
 
void validateMatchRecognize (SqlCall call)
 
void validateAggregateParams (SqlCall aggCall, SqlNode filter, SqlNodeList orderList, SqlValidatorScope scope)
 
void validateCall (SqlCall call, SqlValidatorScope scope)
 
SqlNode expandSelectExpr (SqlNode expr, SelectScope scope, SqlSelect select)
 
SqlNode expand (SqlNode expr, SqlValidatorScope scope)
 
SqlNode expandGroupByOrHavingExpr (SqlNode expr, SqlValidatorScope scope, SqlSelect select, boolean havingExpression)
 
boolean isSystemField (RelDataTypeField field)
 
List< List< String > > getFieldOrigins (SqlNode sqlQuery)
 
RelDataType getParameterRowType (SqlNode sqlQuery)
 
void validateColumnListParams (SqlFunction function, List< RelDataType > argTypes, List< SqlNode > operands)
 

Static Public Attributes

static final Logger TRACER = CalciteTrace.PARSER_LOGGER
 
static final String UPDATE_SRC_ALIAS = "SYS$SRC"
 
static final String UPDATE_TGT_ALIAS = "SYS$TGT"
 
static final String UPDATE_ANON_PREFIX = "SYS$ANON"
 

Protected Member Functions

 SqlValidatorImpl (SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, Config config)
 
void validateNamespace (final SqlValidatorNamespace namespace, RelDataType targetRowType)
 
SqlNode performUnconditionalRewrites (SqlNode node, boolean underFrom)
 
SqlNode getSelfJoinExprForUpdate (SqlNode table, String alias)
 
SqlSelect createSourceSelectForUpdate (SqlUpdate call)
 
SqlSelect createSourceSelectForDelete (SqlDelete call)
 
void inferUnknownTypes (@Nonnull RelDataType inferredType,@Nonnull SqlValidatorScope scope,@Nonnull SqlNode node)
 
void addToSelectList (List< SqlNode > list, Set< String > aliases, List< Map.Entry< String, RelDataType >> fieldList, SqlNode exp, SelectScope scope, final boolean includeSystemVars)
 
boolean shouldAllowIntermediateOrderBy ()
 
MatchRecognizeNamespace createMatchRecognizeNameSpace (SqlMatchRecognize call, SqlNode enclosingNode)
 
void registerNamespace (SqlValidatorScope usingScope, String alias, SqlValidatorNamespace ns, boolean forceNullable)
 
boolean shouldAllowOverRelation ()
 
SelectNamespace createSelectNamespace (SqlSelect select, SqlNode enclosingNode)
 
SetopNamespace createSetopNamespace (SqlCall call, SqlNode enclosingNode)
 
boolean isNestedAggregateWindow (SqlNode node)
 
boolean isOverAggregateWindow (SqlNode node)
 
SqlNode getAggregate (SqlSelect select)
 
void validateFrom (SqlNode node, RelDataType targetRowType, SqlValidatorScope scope)
 
void validateOver (SqlCall call, SqlValidatorScope scope)
 
void validateUnnest (SqlCall call, SqlValidatorScope scope, RelDataType targetRowType)
 
void validateJoin (SqlJoin join, SqlValidatorScope scope)
 
void validateSelect (SqlSelect select, RelDataType targetRowType)
 
void validateWindowClause (SqlSelect select)
 
void validateOrderList (SqlSelect select)
 
void validateGroupClause (SqlSelect select)
 
void validateWhereClause (SqlSelect select)
 
void validateWhereOrOn (SqlValidatorScope scope, SqlNode condition, String clause)
 
void validateHavingClause (SqlSelect select)
 
RelDataType validateSelectList (final SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType)
 
RelDataType createTargetRowType (SqlValidatorTable table, SqlNodeList targetColumnList, boolean append)
 
RelDataType getLogicalTargetRowType (RelDataType targetRowType, SqlInsert insert)
 
RelDataType getLogicalSourceRowType (RelDataType sourceRowType, SqlInsert insert)
 
void checkTypeAssignment (SqlValidatorScope sourceScope, SqlValidatorTable table, RelDataType sourceRowType, RelDataType targetRowType, final SqlNode query)
 
void validateValues (SqlCall node, RelDataType targetRowType, final SqlValidatorScope scope)
 
SqlWindow getWindowByName (SqlIdentifier id, SqlValidatorScope scope)
 
void validateFeature (Feature feature, SqlParserPos context)
 

Protected Attributes

final Map< String, IdInfoidPositions = new HashMap<>()
 
final Map< SqlNode,
SqlValidatorScope > 
scopes
 
final Map< SqlNode,
SqlValidatorNamespace > 
namespaces
 
final Deque< FunctionParamInfofunctionCallStack
 
final RelDataTypeFactory typeFactory
 
final RelDataType unknownType
 

Package Functions

void lookupSelectHints (SqlSelect select, SqlParserPos pos, Collection< SqlMoniker > hintList)
 
RelDataType getTableConstructorRowType (SqlCall values, SqlValidatorScope scope)
 
RelDataType deriveTypeImpl (SqlValidatorScope scope, SqlNode operand)
 
SqlValidatorNamespace lookupFieldNamespace (RelDataType rowType, String name)
 

Package Attributes

final SqlValidatorCatalogReader catalogReader
 

Private Member Functions

boolean expandSelectItem (final SqlNode selectItem, SqlSelect select, RelDataType targetType, List< SqlNode > selectItems, Set< String > aliases, List< Map.Entry< String, RelDataType >> fields, final boolean includeSystemVars)
 
boolean expandStar (List< SqlNode > selectItems, Set< String > aliases, List< Map.Entry< String, RelDataType >> fields, boolean includeSystemVars, SelectScope scope, SqlNode node)
 
SqlNode maybeCast (SqlNode node, RelDataType currentType, RelDataType desiredType)
 
boolean addOrExpandField (List< SqlNode > selectItems, Set< String > aliases, List< Map.Entry< String, RelDataType >> fields, boolean includeSystemVars, SelectScope scope, SqlIdentifier id, RelDataTypeField field)
 
void lookupSelectHints (SqlValidatorNamespace ns, SqlParserPos pos, Collection< SqlMoniker > hintList)
 
void lookupFromHints (SqlNode node, SqlValidatorScope scope, SqlParserPos pos, Collection< SqlMoniker > hintList)
 
void lookupJoinHints (SqlJoin join, SqlValidatorScope scope, SqlParserPos pos, Collection< SqlMoniker > hintList)
 
SqlNode validateScopedExpression (SqlNode topNode, SqlValidatorScope scope)
 
SqlValidatorNamespace getNamespace (SqlNode node, SqlValidatorScope scope)
 
SqlValidatorNamespace getNamespace (SqlIdentifier id, DelegatingScope scope)
 
void handleOffsetFetch (SqlNode offset, SqlNode fetch)
 
SqlSelect getInnerSelect (SqlNode node)
 
void rewriteMerge (SqlMerge call)
 
SqlNode rewriteUpdateToMerge (SqlUpdate updateCall, SqlNode selfJoinSrcExpr)
 
void registerMatchRecognize (SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlMatchRecognize call, SqlNode enclosingNode, String alias, boolean forceNullable)
 
SqlNode registerFrom (SqlValidatorScope parentScope, SqlValidatorScope usingScope, boolean register, final SqlNode node, SqlNode enclosingNode, String alias, SqlNodeList extendList, boolean forceNullable, final boolean lateral)
 
void registerQuery (SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
 
void registerQuery (SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable, boolean checkUpdate)
 
void registerSetop (SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
 
void registerWith (SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlWith with, SqlNode enclosingNode, String alias, boolean forceNullable, boolean checkUpdate)
 
SqlNode getAgg (SqlSelect select)
 
void validateNodeFeature (SqlNode node)
 
void registerSubQueries (SqlValidatorScope parentScope, SqlNode node)
 
void registerOperandSubQueries (SqlValidatorScope parentScope, SqlCall call, int operandOrdinal)
 
void validateLiteralAsDouble (SqlLiteral literal)
 
void checkRollUpInUsing (SqlIdentifier identifier, SqlNode leftOrRight, SqlValidatorScope scope)
 
void validateNoAggs (AggFinder aggFinder, SqlNode node, String clause)
 
RelDataType validateUsingCol (SqlIdentifier id, SqlNode leftOrRight)
 
void checkRollUpInSelectList (SqlSelect select)
 
void checkRollUpInGroupBy (SqlSelect select)
 
void checkRollUpInOrderBy (SqlSelect select)
 
void checkRollUpInWindow (SqlWindow window, SqlValidatorScope scope)
 
void checkRollUpInWindowDecl (SqlSelect select)
 
SqlNode stripDot (SqlNode node)
 
void checkRollUp (SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)
 
void checkRollUp (SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope)
 
SqlWindow getWindowInOver (SqlNode over)
 
Pair< String, String > findTableColumnPair (SqlIdentifier identifier, SqlValidatorScope scope)
 
boolean isRolledUpColumnAllowedInAgg (SqlIdentifier identifier, SqlValidatorScope scope, SqlCall aggCall, SqlNode parent)
 
boolean isRolledUpColumn (SqlIdentifier identifier, SqlValidatorScope scope)
 
boolean shouldCheckForRollUp (SqlNode from)
 
void validateModality (SqlNode query)
 
SqlModality deduceModality (SqlNode query)
 
boolean hasSortedPrefix (SelectScope scope, SqlNodeList orderList)
 
boolean isSortCompatible (SelectScope scope, SqlNode node, boolean descending)
 
void validateGroupByItem (SqlSelect select, SqlNode groupByItem)
 
void validateGroupByExpr (SqlNode groupByItem, SqlValidatorScope groupByScope)
 
void validateOrderItem (SqlSelect select, SqlNode orderItem)
 
void validateGroupItem (SqlValidatorScope groupScope, AggregatingSelectScope aggregatingScope, SqlNode groupItem)
 
void validateGroupingSets (SqlValidatorScope groupScope, AggregatingSelectScope aggregatingScope, SqlCall groupItem)
 
void validateExpr (SqlNode expr, SqlValidatorScope scope)
 
void handleScalarSubQuery (SqlSelect parentSelect, SqlSelect selectItem, List< SqlNode > expandedSelectItems, Set< String > aliasList, List< Map.Entry< String, RelDataType >> fieldList)
 
void checkConstraint (SqlValidatorTable validatorTable, SqlNode source, RelDataType targetRowType)
 
void checkConstraint (SqlValidatorTable validatorTable, SqlUpdate update, RelDataType targetRowType)
 
void checkFieldCount (SqlNode node, SqlValidatorTable table, List< ColumnStrategy > strategies, RelDataType targetRowTypeToValidate, RelDataType realTargetRowType, SqlNode source, RelDataType logicalSourceRowType, RelDataType logicalTargetRowType)
 
boolean isValuesWithDefault (SqlNode source, int column)
 
boolean isRowWithDefault (SqlNode operand, int column)
 
SqlNode getNthExpr (SqlNode query, int ordinal, int sourceCount)
 
void validateAccess (SqlNode node, SqlValidatorTable table, SqlAccessEnum requiredAccess)
 
void validateSnapshot (SqlNode node, SqlValidatorScope scope, SqlValidatorNamespace ns)
 
List< Map.Entry< String,
RelDataType > > 
validateMeasure (SqlMatchRecognize mr, MatchRecognizeScope scope, boolean allRows)
 
SqlNode navigationInMeasure (SqlNode node, boolean allRows)
 
void validateDefinitions (SqlMatchRecognize mr, MatchRecognizeScope scope)
 
SqlNode navigationInDefine (SqlNode node, String alpha)
 
List< String > getFieldOrigin (SqlNode sqlQuery, int i)
 

Static Private Member Functions

static SqlNode expandExprFromJoin (SqlJoin join, SqlIdentifier identifier, SelectScope scope)
 
static SqlNode expandCommonColumn (SqlSelect sqlSelect, SqlNode selectItem, SelectScope scope, SqlValidatorImpl validator)
 
static void validateQualifiedCommonColumn (SqlJoin join, SqlIdentifier identifier, SelectScope scope, SqlValidatorImpl validator)
 
static void findAllValidUdfNames (List< String > names, SqlValidator validator, Collection< SqlMoniker > result)
 
static void findAllValidFunctionNames (List< String > names, SqlValidator validator, Collection< SqlMoniker > result, SqlParserPos pos)
 
static SqlNode stripOver (SqlNode node)
 
static String alias (SqlNode item)
 
static boolean isPhysicalNavigation (SqlKind kind)
 
static boolean isLogicalNavigation (SqlKind kind)
 
static boolean isAggregation (SqlKind kind)
 
static boolean isRunningOrFinal (SqlKind kind)
 
static boolean isSingleVarRequired (SqlKind kind)
 

Private Attributes

final SqlOperatorTable opTab
 
final Map< IdPair< SqlSelect,
Clause >, SqlValidatorScope > 
clauseScopes = new HashMap<>()
 
TableScope tableScope = null
 
final Set< SqlNode > cursorSet = Sets.newIdentityHashSet()
 
int nextGeneratedId
 
final RelDataType booleanType
 
final Map< SqlNode, RelDataType > nodeToTypeMap
 
final AggFinder aggFinder
 
final AggFinder aggOrOverFinder
 
final AggFinder aggOrOverOrGroupFinder
 
final AggFinder groupFinder
 
final AggFinder overFinder
 
Config config
 
final Map< SqlNode, SqlNode > originalExprs = new HashMap<>()
 
SqlNode top
 
boolean validatingSqlMerge
 
boolean inWindow
 
final
SqlValidatorImpl.ValidationErrorFunction 
validationErrorFunction
 
TypeCoercion typeCoercion
 

Detailed Description

Default implementation of SqlValidator.

Definition at line 178 of file SqlValidatorImpl.java.

Constructor & Destructor Documentation

org.apache.calcite.sql.validate.SqlValidatorImpl.SqlValidatorImpl ( SqlOperatorTable  opTab,
SqlValidatorCatalogReader  catalogReader,
RelDataTypeFactory  typeFactory,
Config  config 
)
inlineprotected

Creates a validator.

Parameters
opTabOperator table
catalogReaderCatalog reader
typeFactoryType factory
configConfig

Definition at line 299 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.aggFinder, org.apache.calcite.sql.validate.SqlValidatorImpl.aggOrOverFinder, org.apache.calcite.sql.validate.SqlValidatorImpl.aggOrOverOrGroupFinder, org.apache.calcite.sql.validate.SqlValidatorImpl.booleanType, org.apache.calcite.sql.validate.SqlValidatorImpl.catalogReader, org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.groupFinder, org.apache.calcite.sql.validate.SqlValidatorImpl.opTab, org.apache.calcite.sql.validate.SqlValidatorImpl.overFinder, org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory, and org.apache.calcite.sql.validate.SqlValidatorImpl.unknownType.

303  {
304  this.opTab = Objects.requireNonNull(opTab);
305  this.catalogReader = Objects.requireNonNull(catalogReader);
306  this.typeFactory = Objects.requireNonNull(typeFactory);
307  this.config = Objects.requireNonNull(config);
308 
309  unknownType = typeFactory.createUnknownType();
310  booleanType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
311 
312  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
313  aggFinder = new AggFinder(opTab, false, true, false, null, nameMatcher);
315  new AggFinder(opTab, true, true, false, null, nameMatcher);
316  overFinder = new AggFinder(opTab, true, false, false, aggOrOverFinder,
317  nameMatcher);
318  groupFinder = new AggFinder(opTab, false, false, true, null, nameMatcher);
319  aggOrOverOrGroupFinder = new AggFinder(opTab, true, true, true, null,
320  nameMatcher);
321  // this.typeCoercion = config.typeCoercionFactory().create(typeFactory, this); // HEAVY.AI original
322  this.typeCoercion = TypeCoercions.createHeavyDBTypeCoercion(typeFactory, this); // HEAVY.AI new
323  if (config.typeCoercionRules() != null) {
324  SqlTypeCoercionRule.THREAD_PROVIDERS.set(config.typeCoercionRules());
325  }
326  }

+ Here is the call graph for this function:

Member Function Documentation

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.addOrExpandField ( List< SqlNode >  selectItems,
Set< String >  aliases,
List< Map.Entry< String, RelDataType >>  fields,
boolean  includeSystemVars,
SelectScope  scope,
SqlIdentifier  id,
RelDataTypeField  field 
)
inlineprivate

Definition at line 722 of file SqlValidatorImpl.java.

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

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar().

724  {
725  switch (field.getType().getStructKind()) {
726  case PEEK_FIELDS:
727  case PEEK_FIELDS_DEFAULT:
728  final SqlNode starExp = id.plusStar();
729  expandStar(
730  selectItems,
731  aliases,
732  fields,
733  includeSystemVars,
734  scope,
735  starExp);
736  return true;
737 
738  default:
740  selectItems,
741  aliases,
742  fields,
743  id,
744  scope,
745  includeSystemVars);
746  }
747 
748  return false;
749  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
void addToSelectList(List< SqlNode > list, Set< String > aliases, List< Map.Entry< String, RelDataType >> fieldList, SqlNode exp, SelectScope scope, final boolean includeSystemVars)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.addToSelectList ( List< SqlNode >  list,
Set< String >  aliases,
List< Map.Entry< String, RelDataType >>  fieldList,
SqlNode  exp,
SelectScope  scope,
final boolean  includeSystemVars 
)
inlineprotected

Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list.

Definition at line 1984 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), and org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.addOrExpandField(), and org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar().

1990  {
1991  String alias = SqlValidatorUtil.getAlias(exp, -1);
1992  String uniqueAlias =
1993  SqlValidatorUtil.uniquify(
1994  alias, aliases, SqlValidatorUtil.EXPR_SUGGESTER);
1995  if (!Objects.equals(alias, uniqueAlias)) {
1996  exp = SqlValidatorUtil.addAlias(exp, uniqueAlias);
1997  }
1998  fieldList.add(Pair.of(uniqueAlias, deriveType(scope, exp)));
1999  list.add(exp);
2000  }
RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static String org.apache.calcite.sql.validate.SqlValidatorImpl.alias ( SqlNode  item)
inlinestaticprivate
void org.apache.calcite.sql.validate.SqlValidatorImpl.checkConstraint ( SqlValidatorTable  validatorTable,
SqlNode  source,
RelDataType  targetRowType 
)
inlineprivate

Validates insert values against the constraint of a modifiable view.

Parameters
validatorTableTable that may wrap a ModifiableViewTable
sourceThe values being inserted
targetRowTypeThe target type for the view

Definition at line 4431 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateUpdate().

4434  {
4435  final ModifiableViewTable modifiableViewTable =
4436  validatorTable.unwrap(ModifiableViewTable.class);
4437  if (modifiableViewTable != null && source instanceof SqlCall) {
4438  final Table table = modifiableViewTable.unwrap(Table.class);
4439  final RelDataType tableRowType = table.getRowType(typeFactory);
4440  final List<RelDataTypeField> tableFields = tableRowType.getFieldList();
4441 
4442  // Get the mapping from column indexes of the underlying table
4443  // to the target columns and view constraints.
4444  final Map<Integer, RelDataTypeField> tableIndexToTargetField =
4445  SqlValidatorUtil.getIndexToFieldMap(tableFields, targetRowType);
4446  final Map<Integer, RexNode> projectMap =
4447  RelOptUtil.getColumnConstraints(modifiableViewTable, targetRowType, typeFactory);
4448 
4449  // Determine columns (indexed to the underlying table) that need
4450  // to be validated against the view constraint.
4451  final ImmutableBitSet targetColumns =
4452  ImmutableBitSet.of(tableIndexToTargetField.keySet());
4453  final ImmutableBitSet constrainedColumns =
4454  ImmutableBitSet.of(projectMap.keySet());
4455  final ImmutableBitSet constrainedTargetColumns =
4456  targetColumns.intersect(constrainedColumns);
4457 
4458  // Validate insert values against the view constraint.
4459  final List<SqlNode> values = ((SqlCall) source).getOperandList();
4460  for (final int colIndex : constrainedTargetColumns.asList()) {
4461  final String colName = tableFields.get(colIndex).getName();
4462  final RelDataTypeField targetField = tableIndexToTargetField.get(colIndex);
4463  for (SqlNode row : values) {
4464  final SqlCall call = (SqlCall) row;
4465  final SqlNode sourceValue = call.operand(targetField.getIndex());
4466  final ValidationError validationError =
4467  new ValidationError(sourceValue,
4468  RESOURCE.viewConstraintNotSatisfied(colName,
4469  Util.last(validatorTable.getQualifiedName())));
4470  RelOptUtil.validateValueAgainstConstraint(sourceValue,
4471  projectMap.get(colIndex), validationError);
4472  }
4473  }
4474  }
4475  }

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkConstraint ( SqlValidatorTable  validatorTable,
SqlUpdate  update,
RelDataType  targetRowType 
)
inlineprivate

Validates updates against the constraint of a modifiable view.

Parameters
validatorTableA SqlValidatorTable that may wrap a ModifiableViewTable
updateThe UPDATE parse tree node
targetRowTypeThe target type

Definition at line 4485 of file SqlValidatorImpl.java.

References Integer, and org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

4488  {
4489  final ModifiableViewTable modifiableViewTable =
4490  validatorTable.unwrap(ModifiableViewTable.class);
4491  if (modifiableViewTable != null) {
4492  final Table table = modifiableViewTable.unwrap(Table.class);
4493  final RelDataType tableRowType = table.getRowType(typeFactory);
4494 
4495  final Map<Integer, RexNode> projectMap =
4496  RelOptUtil.getColumnConstraints(modifiableViewTable, targetRowType,
4497  typeFactory);
4498  final Map<String, Integer> nameToIndex =
4499  SqlValidatorUtil.mapNameToIndex(tableRowType.getFieldList());
4500 
4501  // Validate update values against the view constraint.
4502  final List<SqlNode> targets = update.getTargetColumnList().getList();
4503  final List<SqlNode> sources = update.getSourceExpressionList().getList();
4504  for (final Pair<SqlNode, SqlNode> column : Pair.zip(targets, sources)) {
4505  final String columnName = ((SqlIdentifier) column.left).getSimple();
4506  final Integer columnIndex = nameToIndex.get(columnName);
4507  if (projectMap.containsKey(columnIndex)) {
4508  final RexNode columnConstraint = projectMap.get(columnIndex);
4509  final ValidationError validationError =
4510  new ValidationError(column.right,
4511  RESOURCE.viewConstraintNotSatisfied(columnName,
4512  Util.last(validatorTable.getQualifiedName())));
4513  RelOptUtil.validateValueAgainstConstraint(column.right,
4514  columnConstraint, validationError);
4515  }
4516  }
4517  }
4518  }
void org.apache.calcite.sql.validate.SqlValidatorImpl.checkFieldCount ( SqlNode  node,
SqlValidatorTable  table,
List< ColumnStrategy >  strategies,
RelDataType  targetRowTypeToValidate,
RelDataType  realTargetRowType,
SqlNode  source,
RelDataType  logicalSourceRowType,
RelDataType  logicalTargetRowType 
)
inlineprivate

Check the field count of sql insert source and target node row type.

Parameters
nodetarget table sql identifier
tabletarget table
strategiescolumn strategies of target table
targetRowTypeToValidaterow type to validate mainly for column strategies
realTargetRowTypetarget table row type exclusive virtual columns
sourcesource node
logicalSourceRowTypesource node row type
logicalTargetRowTypelogical target row type, contains only target columns if they are specified or if the sql dialect allows subset insert, make a subset of fields(start from the left first field) whose length is equals with the source row type fields number

Definition at line 4535 of file SqlValidatorImpl.java.

References field(), org.apache.calcite.sql.validate.SqlValidatorImpl.isValuesWithDefault(), and org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert().

4538  {
4539  final int sourceFieldCount = logicalSourceRowType.getFieldCount();
4540  final int targetFieldCount = logicalTargetRowType.getFieldCount();
4541  final int targetRealFieldCount = realTargetRowType.getFieldCount();
4542  if (sourceFieldCount != targetFieldCount
4543  && sourceFieldCount != targetRealFieldCount) {
4544  // Allows the source row fields count to be equal with either
4545  // the logical or the real(excludes columns that can not insert into)
4546  // target row fields count.
4547  throw newValidationError(node,
4548  RESOURCE.unmatchInsertColumn(targetFieldCount, sourceFieldCount));
4549  }
4550  // Ensure that non-nullable fields are targeted.
4551  for (final RelDataTypeField field : table.getRowType().getFieldList()) {
4552  final RelDataTypeField targetField =
4553  targetRowTypeToValidate.getField(field.getName(), true, false);
4554  switch (strategies.get(field.getIndex())) {
4555  case NOT_NULLABLE:
4556  assert !field.getType().isNullable();
4557  if (targetField == null) {
4558  throw newValidationError(node,
4559  RESOURCE.columnNotNullable(field.getName()));
4560  }
4561  break;
4562  case NULLABLE:
4563  assert field.getType().isNullable();
4564  break;
4565  case VIRTUAL:
4566  case STORED:
4567  if (targetField != null
4568  && !isValuesWithDefault(source, targetField.getIndex())) {
4569  throw newValidationError(node,
4570  RESOURCE.insertIntoAlwaysGenerated(field.getName()));
4571  }
4572  }
4573  }
4574  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
boolean isValuesWithDefault(SqlNode source, int column)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp ( SqlNode  grandParent,
SqlNode  parent,
SqlNode  current,
SqlValidatorScope  scope,
String  optionalClause 
)
inlineprivate

Definition at line 3535 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInWindow(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.getWindowInOver(), org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregation(), org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumn(), org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumnAllowedInAgg(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), org.apache.calcite.sql.validate.SqlValidatorImpl.stripDot(), org.apache.calcite.sql.validate.SqlValidatorImpl.stripOver(), and toString().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInGroupBy(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInOrderBy(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInSelectList(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInWindow(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

3536  {
3537  current = stripAs(current);
3538  if (current instanceof SqlCall && !(current instanceof SqlSelect)) {
3539  // Validate OVER separately
3540  checkRollUpInWindow(getWindowInOver(current), scope);
3541  current = stripOver(current);
3542 
3543  List<SqlNode> children = ((SqlCall) stripAs(stripDot(current))).getOperandList();
3544  for (SqlNode child : children) {
3545  checkRollUp(parent, current, child, scope, optionalClause);
3546  }
3547  } else if (current instanceof SqlIdentifier) {
3548  SqlIdentifier id = (SqlIdentifier) current;
3549  if (!id.isStar() && isRolledUpColumn(id, scope)) {
3550  if (!isAggregation(parent.getKind())
3551  || !isRolledUpColumnAllowedInAgg(id, scope, (SqlCall) parent, grandParent)) {
3552  String context = optionalClause != null ? optionalClause : parent.getKind().toString();
3553  throw newValidationError(id,
3554  RESOURCE.rolledUpNotAllowed(deriveAlias(id, 0), context));
3555  }
3556  }
3557  }
3558  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
void checkRollUpInWindow(SqlWindow window, SqlValidatorScope scope)
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
boolean isRolledUpColumnAllowedInAgg(SqlIdentifier identifier, SqlValidatorScope scope, SqlCall aggCall, SqlNode parent)
boolean isRolledUpColumn(SqlIdentifier identifier, SqlValidatorScope scope)
void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp ( SqlNode  grandParent,
SqlNode  parent,
SqlNode  current,
SqlValidatorScope  scope 
)
inlineprivate

Definition at line 3560 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp().

3561  {
3562  checkRollUp(grandParent, parent, current, scope, null);
3563  }
void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)

+ Here is the call graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInGroupBy ( SqlSelect  select)
inlineprivate

Definition at line 3492 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), and org.apache.calcite.sql.validate.SqlValidatorImpl.getGroupScope().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

3492  {
3493  SqlNodeList group = select.getGroup();
3494  if (group != null) {
3495  for (SqlNode node : group) {
3496  checkRollUp(null, select, node, getGroupScope(select), "GROUP BY");
3497  }
3498  }
3499  }
SqlValidatorScope getGroupScope(SqlSelect select)
void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInOrderBy ( SqlSelect  select)
inlineprivate

Definition at line 3501 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), and org.apache.calcite.sql.validate.SqlValidatorImpl.getOrderScope().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

3501  {
3502  SqlNodeList orderList = select.getOrderList();
3503  if (orderList != null) {
3504  for (SqlNode node : orderList) {
3505  checkRollUp(null, select, node, getOrderScope(select), "ORDER BY");
3506  }
3507  }
3508  }
SqlValidatorScope getOrderScope(SqlSelect select)
void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInSelectList ( SqlSelect  select)
inlineprivate

Definition at line 3485 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), and org.apache.calcite.sql.validate.SqlValidatorImpl.getSelectScope().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

3485  {
3486  SqlValidatorScope scope = getSelectScope(select);
3487  for (SqlNode item : select.getSelectList()) {
3488  checkRollUp(null, select, item, scope);
3489  }
3490  }
SqlValidatorScope getSelectScope(SqlSelect select)
void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInUsing ( SqlIdentifier  identifier,
SqlNode  leftOrRight,
SqlValidatorScope  scope 
)
inlineprivate

Definition at line 3219 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), and org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin().

3220  {
3221  SqlValidatorNamespace namespace = getNamespace(leftOrRight, scope);
3222  if (namespace != null) {
3223  SqlValidatorTable sqlValidatorTable = namespace.getTable();
3224  if (sqlValidatorTable != null) {
3225  Table table = sqlValidatorTable.unwrap(Table.class);
3226  String column = Util.last(identifier.names);
3227 
3228  if (table.isRolledUp(column)) {
3229  throw newValidationError(identifier,
3230  RESOURCE.rolledUpNotAllowed(column, "USING"));
3231  }
3232  }
3233  }
3234  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInWindow ( SqlWindow  window,
SqlValidatorScope  scope 
)
inlineprivate

Definition at line 3510 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), and org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInWindowDecl().

3510  {
3511  if (window != null) {
3512  for (SqlNode node : window.getPartitionList()) {
3513  checkRollUp(null, window, node, scope, "PARTITION BY");
3514  }
3515 
3516  for (SqlNode node : window.getOrderList()) {
3517  checkRollUp(null, window, node, scope, "ORDER BY");
3518  }
3519  }
3520  }
void checkRollUp(SqlNode grandParent, SqlNode parent, SqlNode current, SqlValidatorScope scope, String optionalClause)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInWindowDecl ( SqlSelect  select)
inlineprivate

Definition at line 3522 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInWindow(), and org.apache.calcite.sql.validate.SqlValidatorImpl.getSelectScope().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

3522  {
3523  for (SqlNode decl : select.getWindowList()) {
3524  checkRollUpInWindow((SqlWindow) decl, getSelectScope(select));
3525  }
3526  }
void checkRollUpInWindow(SqlWindow window, SqlValidatorScope scope)
SqlValidatorScope getSelectScope(SqlSelect select)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.checkTypeAssignment ( SqlValidatorScope  sourceScope,
SqlValidatorTable  table,
RelDataType  sourceRowType,
RelDataType  targetRowType,
final SqlNode  query 
)
inlineprotected

Checks the type assignment of an INSERT or UPDATE query.

Skip the virtual columns(can not insert into) type assignment check if the source fields count equals with the real target table fields count, see how checkFieldCount was used.

Parameters
sourceScopeScope of query source which is used to infer node type
tableTarget table
sourceRowTypeSource row type
targetRowTypeTarget row type, it should either contain all the virtual columns (can not insert into) or exclude all the virtual columns
queryThe query

Definition at line 4645 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNthExpr(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), and org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateUpdate().

4650  {
4651  // NOTE jvs 23-Feb-2006: subclasses may allow for extra targets
4652  // representing system-maintained columns, so stop after all sources
4653  // matched
4654  boolean isUpdateModifiableViewTable = false;
4655  if (query instanceof SqlUpdate) {
4656  final SqlNodeList targetColumnList = ((SqlUpdate) query).getTargetColumnList();
4657  if (targetColumnList != null) {
4658  final int targetColumnCnt = targetColumnList.size();
4659  targetRowType = SqlTypeUtil.extractLastNFields(typeFactory, targetRowType,
4660  targetColumnCnt);
4661  sourceRowType = SqlTypeUtil.extractLastNFields(typeFactory, sourceRowType,
4662  targetColumnCnt);
4663  }
4664  isUpdateModifiableViewTable = table.unwrap(ModifiableViewTable.class) != null;
4665  }
4666  if (SqlTypeUtil.equalAsStructSansNullability(typeFactory,
4667  sourceRowType,
4668  targetRowType,
4669  null)) {
4670  // Returns early if source and target row type equals sans nullability.
4671  return;
4672  }
4673  if (config.typeCoercionEnabled() && !isUpdateModifiableViewTable) {
4674  // Try type coercion first if implicit type coercion is allowed.
4675  boolean coerced = typeCoercion.querySourceCoercion(sourceScope,
4676  sourceRowType,
4677  targetRowType,
4678  query);
4679  if (coerced) {
4680  return;
4681  }
4682  }
4683 
4684  // Fall back to default behavior: compare the type families.
4685  List<RelDataTypeField> sourceFields = sourceRowType.getFieldList();
4686  List<RelDataTypeField> targetFields = targetRowType.getFieldList();
4687  final int sourceCount = sourceFields.size();
4688  for (int i = 0; i < sourceCount; ++i) {
4689  RelDataType sourceType = sourceFields.get(i).getType();
4690  RelDataType targetType = targetFields.get(i).getType();
4691  if (!SqlTypeUtil.canAssignFrom(targetType, sourceType)) {
4692  SqlNode node = getNthExpr(query, i, sourceCount);
4693  if (node instanceof SqlDynamicParam) {
4694  continue;
4695  }
4696  String targetTypeString;
4697  String sourceTypeString;
4698  if (SqlTypeUtil.areCharacterSetsMismatched(
4699  sourceType,
4700  targetType)) {
4701  sourceTypeString = sourceType.getFullTypeString();
4702  targetTypeString = targetType.getFullTypeString();
4703  } else {
4704  sourceTypeString = sourceType.toString();
4705  targetTypeString = targetType.toString();
4706  }
4707  throw newValidationError(node,
4708  RESOURCE.typeNotAssignable(
4709  targetFields.get(i).getName(), targetTypeString,
4710  sourceFields.get(i).getName(), sourceTypeString));
4711  }
4712  }
4713  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
SqlNode getNthExpr(SqlNode query, int ordinal, int sourceCount)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

MatchRecognizeNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.createMatchRecognizeNameSpace ( SqlMatchRecognize  call,
SqlNode  enclosingNode 
)
inlineprotected

Definition at line 2037 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.registerMatchRecognize().

2039  {
2040  return new MatchRecognizeNamespace(this, call, enclosingNode);
2041  }

+ Here is the caller graph for this function:

SelectNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.createSelectNamespace ( SqlSelect  select,
SqlNode  enclosingNode 
)
inlineprotected

Creates a namespace for a SELECT node. Derived class may override this factory method.

Parameters
selectSelect node
enclosingNodeEnclosing node
Returns
Select namespace

Definition at line 2463 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.declareCursor(), and org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery().

2465  {
2466  return new SelectNamespace(this, select, enclosingNode);
2467  }

+ Here is the caller graph for this function:

SetopNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.createSetopNamespace ( SqlCall  call,
SqlNode  enclosingNode 
)
inlineprotected

Creates a namespace for a set operation (UNION, INTERSECT, or EXCEPT). Derived class may override this factory method.

Parameters
callCall to set operation
enclosingNodeEnclosing node
Returns
Set operation namespace

Definition at line 2478 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.registerSetop().

2480  {
2481  return new SetopNamespace(this, call, enclosingNode);
2482  }

+ Here is the caller graph for this function:

SqlSelect org.apache.calcite.sql.validate.SqlValidatorImpl.createSourceSelectForDelete ( SqlDelete  call)
inlineprotected

Creates the SELECT statement that putatively feeds rows into a DELETE statement to be deleted.

Parameters
callCall to the DELETE operator
Returns
select statement

Definition at line 1637 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites().

1637  {
1638  final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
1639  selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
1640  SqlNode sourceTable = call.getTargetTable();
1641  if (call.getAlias() != null) {
1642  sourceTable =
1643  SqlValidatorUtil.addAlias(
1644  sourceTable,
1645  call.getAlias().getSimple());
1646  }
1647  return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable,
1648  call.getCondition(), null, null, null, null, null, null, null);
1649  }

+ Here is the caller graph for this function:

SqlSelect org.apache.calcite.sql.validate.SqlValidatorImpl.createSourceSelectForUpdate ( SqlUpdate  call)
inlineprotected

Creates the SELECT statement that putatively feeds rows into an UPDATE statement to be updated.

Parameters
callCall to the UPDATE operator
Returns
select statement

Definition at line 1608 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites().

1608  {
1609  final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
1610  selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
1611  int ordinal = 0;
1612  for (SqlNode exp : call.getSourceExpressionList()) {
1613  // Force unique aliases to avoid a duplicate for Y with
1614  // SET X=Y
1615  String alias = SqlUtil.deriveAliasFromOrdinal(ordinal);
1616  selectList.add(SqlValidatorUtil.addAlias(exp, alias));
1617  ++ordinal;
1618  }
1619  SqlNode sourceTable = call.getTargetTable();
1620  if (call.getAlias() != null) {
1621  sourceTable =
1622  SqlValidatorUtil.addAlias(
1623  sourceTable,
1624  call.getAlias().getSimple());
1625  }
1626  return new SqlSelect(SqlParserPos.ZERO, null, selectList, sourceTable,
1627  call.getCondition(), null, null, null, null, null, null, null);
1628  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.createTargetRowType ( SqlValidatorTable  table,
SqlNodeList  targetColumnList,
boolean  append 
)
inlineprotected

Derives a row-type for INSERT and UPDATE operations.

Parameters
tableTarget table for INSERT/UPDATE
targetColumnListList of target columns, or null if not specified
appendWhether to append fields to those in baseRowType
Returns
Rowtype

Definition at line 4316 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.catalogReader, org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), and org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMerge(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateUpdate().

4319  {
4320  RelDataType baseRowType = table.getRowType();
4321  if (targetColumnList == null) {
4322  return baseRowType;
4323  }
4324  List<RelDataTypeField> targetFields = baseRowType.getFieldList();
4325  final List<Map.Entry<String, RelDataType>> fields = new ArrayList<>();
4326  if (append) {
4327  for (RelDataTypeField targetField : targetFields) {
4328  fields.add(
4329  Pair.of(SqlUtil.deriveAliasFromOrdinal(fields.size()),
4330  targetField.getType()));
4331  }
4332  }
4333  final Set<Integer> assignedFields = new HashSet<>();
4334  final RelOptTable relOptTable = table instanceof RelOptTable
4335  ? ((RelOptTable) table) : null;
4336  for (SqlNode node : targetColumnList) {
4337  SqlIdentifier id = (SqlIdentifier) node;
4338  RelDataTypeField targetField =
4339  SqlValidatorUtil.getTargetField(
4340  baseRowType, typeFactory, id, catalogReader, relOptTable);
4341  if (targetField == null) {
4342  throw newValidationError(id,
4343  RESOURCE.unknownTargetColumn(id.toString()));
4344  }
4345  if (!assignedFields.add(targetField.getIndex())) {
4346  throw newValidationError(id,
4347  RESOURCE.duplicateTargetColumn(targetField.getName()));
4348  }
4349  fields.add(targetField);
4350  }
4351  return typeFactory.createStructType(fields);
4352  }
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:158
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.declareCursor ( SqlSelect  select,
SqlValidatorScope  parentScope 
)
inline

Definition at line 373 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.createSelectNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.CURSOR, org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.nextGeneratedId, and org.apache.calcite.sql.validate.SqlValidatorImpl.registerNamespace().

373  {
374  cursorSet.add(select);
375 
376  // add the cursor to a map that maps the cursor to its select based on
377  // the position of the cursor relative to other cursors in that call
378  FunctionParamInfo funcParamInfo = functionCallStack.peek();
379  Map<Integer, SqlSelect> cursorMap = funcParamInfo.cursorPosToSelectMap;
380  int numCursors = cursorMap.size();
381  cursorMap.put(numCursors, select);
382 
383  // create a namespace associated with the result of the select
384  // that is the argument to the cursor constructor; register it
385  // with a scope corresponding to the cursor
386  SelectScope cursorScope = new SelectScope(parentScope, null, select);
387  clauseScopes.put(IdPair.of(select, Clause.CURSOR), cursorScope);
388  final SelectNamespace selectNs = createSelectNamespace(select, select);
389  String alias = deriveAlias(select, nextGeneratedId++);
390  registerNamespace(cursorScope, alias, selectNs, false);
391  }
SelectNamespace createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
void registerNamespace(SqlValidatorScope usingScope, String alias, SqlValidatorNamespace ns, boolean forceNullable)

+ Here is the call graph for this function:

SqlModality org.apache.calcite.sql.validate.SqlValidatorImpl.deduceModality ( SqlNode  query)
inlineprivate

Return the intended modality of a SELECT or set-op.

Definition at line 3677 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateModality().

3677  {
3678  if (query instanceof SqlSelect) {
3679  SqlSelect select = (SqlSelect) query;
3680  return select.getModifierNode(SqlSelectKeyword.STREAM) != null
3681  ? SqlModality.STREAM
3682  : SqlModality.RELATION;
3683  } else if (query.getKind() == SqlKind.VALUES) {
3684  return SqlModality.RELATION;
3685  } else {
3686  assert query.isA(SqlKind.SET_QUERY);
3687  final SqlCall call = (SqlCall) query;
3688  return deduceModality(call.getOperandList().get(0));
3689  }
3690  }

+ Here is the caller graph for this function:

String org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias ( SqlNode  node,
int  ordinal 
)
inline
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.deriveConstructorType ( SqlValidatorScope  scope,
SqlCall  call,
SqlFunction  unresolvedConstructor,
SqlFunction  resolvedConstructor,
List< RelDataType >  argTypes 
)
inline

Definition at line 1790 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.handleUnresolvedFunction(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), and run_benchmark_import.type.

1795  {
1796  SqlIdentifier sqlIdentifier = unresolvedConstructor.getSqlIdentifier();
1797  assert sqlIdentifier != null;
1798  RelDataType type = catalogReader.getNamedType(sqlIdentifier);
1799  if (type == null) {
1800  // TODO jvs 12-Feb-2005: proper type name formatting
1801  throw newValidationError(sqlIdentifier,
1802  RESOURCE.unknownDatatypeName(sqlIdentifier.toString()));
1803  }
1804 
1805  if (resolvedConstructor == null) {
1806  if (call.operandCount() > 0) {
1807  // This is not a default constructor invocation, and
1808  // no user-defined constructor could be found
1809  throw handleUnresolvedFunction(call, unresolvedConstructor, argTypes,
1810  null);
1811  }
1812  } else {
1813  SqlCall testCall =
1814  resolvedConstructor.createCall(
1815  call.getParserPosition(),
1816  call.getOperandList());
1817  RelDataType returnType =
1818  resolvedConstructor.validateOperands(
1819  this,
1820  scope,
1821  testCall);
1822  assert type == returnType;
1823  }
1824 
1825  if (config.identifierExpansion()) {
1826  if (resolvedConstructor != null) {
1827  ((SqlBasicCall) call).setOperator(resolvedConstructor);
1828  } else {
1829  // fake a fully-qualified call to the default constructor
1830  ((SqlBasicCall) call).setOperator(
1831  new SqlFunction(
1832  type.getSqlIdentifier(),
1833  ReturnTypes.explicit(type),
1834  null,
1835  null,
1836  null,
1837  SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR));
1838  }
1839  }
1840  return type;
1841  }
CalciteException handleUnresolvedFunction(SqlCall call, SqlFunction unresolvedFunction, List< RelDataType > argTypes, List< String > argNames)
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)

+ Here is the call graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType ( SqlValidatorScope  scope,
SqlNode  expr 
)
inline

Definition at line 1756 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.setValidatedNodeType(), and run_benchmark_import.type.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.addToSelectList(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandOrderExpr(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(), org.apache.calcite.sql.validate.SqlValidatorImpl.getTableConstructorRowType(), org.apache.calcite.sql.validate.SqlValidatorImpl.handleScalarSubQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.inferUnknownTypes(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateDefinitions(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateGroupItem(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateHavingClause(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMatchRecognize(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMeasure(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSnapshot(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateValues(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateWhereOrOn().

1758  {
1759  Objects.requireNonNull(scope);
1760  Objects.requireNonNull(expr);
1761 
1762  // if we already know the type, no need to re-derive
1763  RelDataType type = nodeToTypeMap.get(expr);
1764  if (type != null) {
1765  return type;
1766  }
1767  final SqlValidatorNamespace ns = getNamespace(expr);
1768  if (ns != null) {
1769  return ns.getType();
1770  }
1771  type = deriveTypeImpl(scope, expr);
1772  Preconditions.checkArgument(
1773  type != null,
1774  "SqlValidator.deriveTypeInternal returned null");
1775  setValidatedNodeType(expr, type);
1776  return type;
1777  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
final void setValidatedNodeType(SqlNode node, RelDataType type)
RelDataType deriveTypeImpl(SqlValidatorScope scope, SqlNode operand)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl ( SqlValidatorScope  scope,
SqlNode  operand 
)
inlinepackage

Derives the type of a node, never null.

Definition at line 1782 of file SqlValidatorImpl.java.

References run_benchmark_import.type.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), and org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem().

1784  {
1785  DeriveTypeVisitor v = new DeriveTypeVisitor(scope);
1786  final RelDataType type = operand.accept(v);
1787  return Objects.requireNonNull(scope.nullifyType(operand, type));
1788  }

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.expand ( SqlNode  expr,
SqlValidatorScope  scope 
)
inline

Definition at line 5524 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.setOriginal().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateDefinitions(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMatchRecognize(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMeasure(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateOrderList(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateUnnest(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateWhereClause(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateWindowClause().

5524  {
5525  final Expander expander = new Expander(this, scope);
5526  SqlNode newExpr = expr.accept(expander);
5527  if (expr != newExpr) {
5528  setOriginal(newExpr, expr);
5529  }
5530  return newExpr;
5531  }
void setOriginal(SqlNode expr, SqlNode original)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.expandCommonColumn ( SqlSelect  sqlSelect,
SqlNode  selectItem,
SelectScope  scope,
SqlValidatorImpl  validator 
)
inlinestaticprivate

Definition at line 543 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.config, org.apache.calcite.sql.validate.SqlValidatorImpl.expandExprFromJoin(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateQualifiedCommonColumn().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.SelectExpander.visit(), and org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.visit().

544  {
545  if (!(selectItem instanceof SqlIdentifier)) {
546  return selectItem;
547  }
548 
549  final SqlNode from = sqlSelect.getFrom();
550  if (!(from instanceof SqlJoin)) {
551  return selectItem;
552  }
553 
554  final SqlIdentifier identifier = (SqlIdentifier) selectItem;
555  if (!identifier.isSimple()) {
556  if (!validator.config().sqlConformance().allowQualifyingCommonColumn()) {
557  validateQualifiedCommonColumn((SqlJoin) from, identifier, scope, validator);
558  }
559  return selectItem;
560  }
561 
562  return expandExprFromJoin((SqlJoin) from, identifier, scope);
563  }
static SqlNode expandExprFromJoin(SqlJoin join, SqlIdentifier identifier, SelectScope scope)
static void validateQualifiedCommonColumn(SqlJoin join, SqlIdentifier identifier, SelectScope scope, SqlValidatorImpl validator)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.expandExprFromJoin ( SqlJoin  join,
SqlIdentifier  identifier,
SelectScope  scope 
)
inlinestaticprivate

Definition at line 476 of file SqlValidatorImpl.java.

References Fragmenter_Namespace.indexOf(), and setup.name.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandCommonColumn().

477  {
478  if (join.getConditionType() != JoinConditionType.USING) {
479  return identifier;
480  }
481 
482  for (SqlNode node : (SqlNodeList) join.getCondition()) {
483  final String name = ((SqlIdentifier) node).getSimple();
484  if (identifier.getSimple().equals(name)) {
485  final List<SqlNode> qualifiedNode = new ArrayList<>();
486  for (ScopeChild child : scope.children) {
487  if (child.namespace.getRowType()
488  .getFieldNames().indexOf(name) >= 0) {
489  final SqlIdentifier exp =
490  new SqlIdentifier(
491  ImmutableList.of(child.name, name),
492  identifier.getParserPosition());
493  qualifiedNode.add(exp);
494  }
495  }
496 
497  assert qualifiedNode.size() == 2;
498  final SqlNode finalNode =
499  SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO,
500  SqlStdOperatorTable.COALESCE.createCall(SqlParserPos.ZERO,
501  qualifiedNode.get(0),
502  qualifiedNode.get(1)),
503  new SqlIdentifier(name, SqlParserPos.ZERO));
504  return finalNode;
505  }
506  }
507 
508  // Only need to try to expand the expr from the left input of join
509  // since it is always left-deep join.
510  final SqlNode node = join.getLeft();
511  if (node instanceof SqlJoin) {
512  return expandExprFromJoin((SqlJoin) node, identifier, scope);
513  } else {
514  return identifier;
515  }
516  }
std::string join(T const &container, std::string const &delim)
static SqlNode expandExprFromJoin(SqlJoin join, SqlIdentifier identifier, SelectScope scope)
size_t indexOf(std::vector< T > &vec, T val)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.expandGroupByOrHavingExpr ( SqlNode  expr,
SqlValidatorScope  scope,
SqlSelect  select,
boolean  havingExpression 
)
inline

Definition at line 5533 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.setOriginal().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateGroupClause(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateHavingClause().

5534  {
5535  final Expander expander = new ExtendedExpander(this, scope, select, expr,
5536  havingExpression);
5537  SqlNode newExpr = expr.accept(expander);
5538  if (expr != newExpr) {
5539  setOriginal(newExpr, expr);
5540  }
5541  return newExpr;
5542  }
void setOriginal(SqlNode expr, SqlNode original)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.expandOrderExpr ( SqlSelect  select,
SqlNode  orderExpr 
)
inline

Definition at line 4009 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), org.apache.calcite.sql.validate.SqlValidatorImpl.getOrderScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.inferUnknownTypes(), org.apache.calcite.sql.validate.SqlValidatorImpl.setValidatedNodeType(), run_benchmark_import.type, and org.apache.calcite.sql.validate.SqlValidatorImpl.unknownType.

4009  {
4010  final SqlNode newSqlNode =
4011  new OrderExpressionExpander(select, orderExpr).go();
4012  if (newSqlNode != orderExpr) {
4013  final SqlValidatorScope scope = getOrderScope(select);
4014  inferUnknownTypes(unknownType, scope, newSqlNode);
4015  final RelDataType type = deriveType(scope, newSqlNode);
4016  setValidatedNodeType(newSqlNode, type);
4017  }
4018  return newSqlNode;
4019  }
final void setValidatedNodeType(SqlNode node, RelDataType type)
SqlValidatorScope getOrderScope(SqlSelect select)
RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
void inferUnknownTypes(@Nonnull RelDataType inferredType,@Nonnull SqlValidatorScope scope,@Nonnull SqlNode node)

+ Here is the call graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectExpr ( SqlNode  expr,
SelectScope  scope,
SqlSelect  select 
)
inline

Definition at line 5514 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.setOriginal().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem().

5515  {
5516  final Expander expander = new SelectExpander(this, scope, select);
5517  final SqlNode newExpr = expr.accept(expander);
5518  if (expr != newExpr) {
5519  setOriginal(newExpr, expr);
5520  }
5521  return newExpr;
5522  }
void setOriginal(SqlNode expr, SqlNode original)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem ( final SqlNode  selectItem,
SqlSelect  select,
RelDataType  targetType,
List< SqlNode >  selectItems,
Set< String >  aliases,
List< Map.Entry< String, RelDataType >>  fields,
final boolean  includeSystemVars 
)
inlineprivate

If selectItem is "*" or "TABLE.*", expands it and returns true; otherwise writes the unexpanded item.

Parameters
selectItemSelect-list item
selectContaining select clause
selectItemsList that expanded items are written to
aliasesSet of aliases
fieldsList of field names and types, in alias order
includeSystemVarsIf true include system vars in lists
Returns
Whether the node was expanded

Definition at line 424 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectExpr(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), org.apache.calcite.sql.validate.SqlValidatorImpl.getSelectScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.getWhereScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.inferUnknownTypes(), org.apache.calcite.sql.validate.SqlValidatorImpl.setValidatedNodeType(), and run_benchmark_import.type.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList().

431  {
432  final SelectScope scope = (SelectScope) getWhereScope(select);
433  if (expandStar(selectItems, aliases, fields, includeSystemVars, scope,
434  selectItem)) {
435  return true;
436  }
437 
438  // Expand the select item: fully-qualify columns, and convert
439  // parentheses-free functions such as LOCALTIME into explicit function
440  // calls.
441  SqlNode expanded = expandSelectExpr(selectItem, scope, select);
442  final String alias =
443  deriveAlias(
444  selectItem,
445  aliases.size());
446 
447  // If expansion has altered the natural alias, supply an explicit 'AS'.
448  final SqlValidatorScope selectScope = getSelectScope(select);
449  if (expanded != selectItem) {
450  String newAlias =
451  deriveAlias(
452  expanded,
453  aliases.size());
454  if (!newAlias.equals(alias)) {
455  expanded =
456  SqlStdOperatorTable.AS.createCall(
457  selectItem.getParserPosition(),
458  expanded,
459  new SqlIdentifier(alias, SqlParserPos.ZERO));
460  deriveTypeImpl(selectScope, expanded);
461  }
462  }
463 
464  selectItems.add(expanded);
465  aliases.add(alias);
466 
467  if (expanded != null) {
468  inferUnknownTypes(targetType, scope, expanded);
469  }
470  final RelDataType type = deriveType(selectScope, expanded);
471  setValidatedNodeType(expanded, type);
472  fields.add(Pair.of(alias, type));
473  return false;
474  }
final void setValidatedNodeType(SqlNode node, RelDataType type)
SqlValidatorScope getSelectScope(SqlSelect select)
SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
SqlNode expandSelectExpr(SqlNode expr, SelectScope scope, SqlSelect select)
void inferUnknownTypes(@Nonnull RelDataType inferredType,@Nonnull SqlValidatorScope scope,@Nonnull SqlNode node)
RelDataType deriveTypeImpl(SqlValidatorScope scope, SqlNode operand)
SqlValidatorScope getWhereScope(SqlSelect select)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNodeList org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar ( SqlNodeList  selectList,
SqlSelect  select,
boolean  includeSystemVars 
)
inline

Definition at line 350 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(), org.apache.calcite.sql.validate.SqlValidatorImpl.getRawSelectScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeTypeIfKnown(), and org.apache.calcite.sql.validate.SqlValidatorImpl.unknownType.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.addOrExpandField(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(), and org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.nthSelectItem().

353  {
354  final List<SqlNode> list = new ArrayList<>();
355  final List<Map.Entry<String, RelDataType>> types = new ArrayList<>();
356  for (int i = 0; i < selectList.size(); i++) {
357  final SqlNode selectItem = selectList.get(i);
358  final RelDataType originalType = getValidatedNodeTypeIfKnown(selectItem);
360  selectItem,
361  select,
362  Util.first(originalType, unknownType),
363  list,
364  catalogReader.nameMatcher().createSet(),
365  types,
366  includeSystemVars);
367  }
368  getRawSelectScope(select).setExpandedSelectList(list);
369  return new SqlNodeList(list, SqlParserPos.ZERO);
370  }
boolean expandSelectItem(final SqlNode selectItem, SqlSelect select, RelDataType targetType, List< SqlNode > selectItems, Set< String > aliases, List< Map.Entry< String, RelDataType >> fields, final boolean includeSystemVars)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar ( List< SqlNode >  selectItems,
Set< String >  aliases,
List< Map.Entry< String, RelDataType >>  fields,
boolean  includeSystemVars,
SelectScope  scope,
SqlNode  node 
)
inlineprivate

Definition at line 592 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.addOrExpandField(), org.apache.calcite.sql.validate.SqlValidatorImpl.addToSelectList(), field(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumn(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), run_benchmark_import.type, and org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

594  {
595  if (!(node instanceof SqlIdentifier)) {
596  return false;
597  }
598  final SqlIdentifier identifier = (SqlIdentifier) node;
599  if (!identifier.isStar()) {
600  return false;
601  }
602  final SqlParserPos startPosition = identifier.getParserPosition();
603  switch (identifier.names.size()) {
604  case 1:
605  boolean hasDynamicStruct = false;
606  for (ScopeChild child : scope.children) {
607  final int before = fields.size();
608  if (child.namespace.getRowType().isDynamicStruct()) {
609  hasDynamicStruct = true;
610  // don't expand star if the underneath table is dynamic.
611  // Treat this star as a special field in validation/conversion and
612  // wait until execution time to expand this star.
613  final SqlNode exp =
614  new SqlIdentifier(
615  ImmutableList.of(child.name,
616  DynamicRecordType.DYNAMIC_STAR_PREFIX),
617  startPosition);
619  selectItems,
620  aliases,
621  fields,
622  exp,
623  scope,
624  includeSystemVars);
625  } else {
626  final SqlNode from = child.namespace.getNode();
627  final SqlValidatorNamespace fromNs = getNamespace(from, scope);
628  assert fromNs != null;
629  final RelDataType rowType = fromNs.getRowType();
630  for (RelDataTypeField field : rowType.getFieldList()) {
631  String columnName = field.getName();
632 
633  // TODO: do real implicit collation here
634  final SqlIdentifier exp =
635  new SqlIdentifier(
636  ImmutableList.of(child.name, columnName),
637  startPosition);
638  // Don't add expanded rolled up columns
639  if (!isRolledUpColumn(exp, scope)) {
641  selectItems,
642  aliases,
643  fields,
644  includeSystemVars,
645  scope,
646  exp,
647  field);
648  }
649  }
650  }
651  if (child.nullable) {
652  for (int i = before; i < fields.size(); i++) {
653  final Map.Entry<String, RelDataType> entry = fields.get(i);
654  final RelDataType type = entry.getValue();
655  if (!type.isNullable()) {
656  fields.set(i,
657  Pair.of(entry.getKey(),
658  typeFactory.createTypeWithNullability(type, true)));
659  }
660  }
661  }
662  }
663  // If NATURAL JOIN or USING is present, move key fields to the front of
664  // the list, per standard SQL. Disabled if there are dynamic fields.
665  if (!hasDynamicStruct || Bug.CALCITE_2400_FIXED) {
666  new Permute(scope.getNode().getFrom(), 0).permute(selectItems, fields);
667  }
668  return true;
669 
670  default:
671  final SqlIdentifier prefixId = identifier.skipLast(1);
672  final SqlValidatorScope.ResolvedImpl resolved =
673  new SqlValidatorScope.ResolvedImpl();
674  final SqlNameMatcher nameMatcher =
675  scope.validator.catalogReader.nameMatcher();
676  scope.resolve(prefixId.names, nameMatcher, true, resolved);
677  if (resolved.count() == 0) {
678  // e.g. "select s.t.* from e"
679  // or "select r.* from e"
680  throw newValidationError(prefixId,
681  RESOURCE.unknownIdentifier(prefixId.toString()));
682  }
683  final RelDataType rowType = resolved.only().rowType();
684  if (rowType.isDynamicStruct()) {
685  // don't expand star if the underneath table is dynamic.
687  selectItems,
688  aliases,
689  fields,
690  prefixId.plus(DynamicRecordType.DYNAMIC_STAR_PREFIX, startPosition),
691  scope,
692  includeSystemVars);
693  } else if (rowType.isStruct()) {
694  for (RelDataTypeField field : rowType.getFieldList()) {
695  String columnName = field.getName();
696 
697  // TODO: do real implicit collation here
699  selectItems,
700  aliases,
701  fields,
702  includeSystemVars,
703  scope,
704  prefixId.plus(columnName, startPosition),
705  field);
706  }
707  } else {
708  throw newValidationError(prefixId, RESOURCE.starRequiresRecordType());
709  }
710  return true;
711  }
712  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
boolean addOrExpandField(List< SqlNode > selectItems, Set< String > aliases, List< Map.Entry< String, RelDataType >> fields, boolean includeSystemVars, SelectScope scope, SqlIdentifier id, RelDataTypeField field)
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
boolean isRolledUpColumn(SqlIdentifier identifier, SqlValidatorScope scope)
void addToSelectList(List< SqlNode > list, Set< String > aliases, List< Map.Entry< String, RelDataType >> fieldList, SqlNode exp, SelectScope scope, final boolean includeSystemVars)

+ Here is the call graph for this function:

static void org.apache.calcite.sql.validate.SqlValidatorImpl.findAllValidFunctionNames ( List< String >  names,
SqlValidator  validator,
Collection< SqlMoniker >  result,
SqlParserPos  pos 
)
inlinestaticprivate

Definition at line 987 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupNameCompletionHints().

991  {
992  // a function name can only be 1 part
993  if (names.size() > 1) {
994  return;
995  }
996  for (SqlOperator op : validator.getOperatorTable().getOperatorList()) {
997  SqlIdentifier curOpId =
998  new SqlIdentifier(
999  op.getName(),
1000  pos);
1001 
1002  final SqlCall call = validator.makeNullaryCall(curOpId);
1003  if (call != null) {
1004  result.add(
1005  new SqlMonikerImpl(
1006  op.getName(),
1007  SqlMonikerType.FUNCTION));
1008  } else {
1009  if ((op.getSyntax() == SqlSyntax.FUNCTION)
1010  || (op.getSyntax() == SqlSyntax.PREFIX)) {
1011  if (op.getOperandTypeChecker() != null) {
1012  String sig = op.getAllowedSignatures();
1013  sig = sig.replace("'", "");
1014  result.add(
1015  new SqlMonikerImpl(
1016  sig,
1017  SqlMonikerType.FUNCTION));
1018  continue;
1019  }
1020  result.add(
1021  new SqlMonikerImpl(
1022  op.getName(),
1023  SqlMonikerType.FUNCTION));
1024  }
1025  }
1026  }
1027  }

+ Here is the caller graph for this function:

static void org.apache.calcite.sql.validate.SqlValidatorImpl.findAllValidUdfNames ( List< String >  names,
SqlValidator  validator,
Collection< SqlMoniker >  result 
)
inlinestaticprivate

Definition at line 971 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupNameCompletionHints().

974  {
975  final List<SqlMoniker> objNames = new ArrayList<>();
976  SqlValidatorUtil.getSchemaObjectMonikers(
977  validator.getCatalogReader(),
978  names,
979  objNames);
980  for (SqlMoniker objName : objNames) {
981  if (objName.getType() == SqlMonikerType.FUNCTION) {
982  result.add(objName);
983  }
984  }
985  }

+ Here is the caller graph for this function:

Pair<String, String> org.apache.calcite.sql.validate.SqlValidatorImpl.findTableColumnPair ( SqlIdentifier  identifier,
SqlValidatorScope  scope 
)
inlineprivate

Definition at line 3586 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.makeNullaryCall().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumn(), and org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumnAllowedInAgg().

3587  {
3588  final SqlCall call = makeNullaryCall(identifier);
3589  if (call != null) {
3590  return null;
3591  }
3592  SqlQualified qualified = scope.fullyQualify(identifier);
3593  List<String> names = qualified.identifier.names;
3594 
3595  if (names.size() < 2) {
3596  return null;
3597  }
3598 
3599  return new Pair<>(names.get(names.size() - 2), Util.last(names));
3600  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.getAgg ( SqlSelect  select)
inlineprivate

If there is at least one call to an aggregate function, returns the first.

Definition at line 2942 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getRawSelectScope().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.getAggregate().

2942  {
2943  final SelectScope selectScope = getRawSelectScope(select);
2944  if (selectScope != null) {
2945  final List<SqlNode> selectList = selectScope.getExpandedSelectList();
2946  if (selectList != null) {
2947  return aggFinder.findAgg(selectList);
2948  }
2949  }
2950  return aggFinder.findAgg(select.getSelectList());
2951  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.getAggregate ( SqlSelect  select)
inlineprotected

Returns the parse tree node (GROUP BY, HAVING, or an aggregate function call) that causes

select

to be an aggregate query, or null if it is not an aggregate query.

The node is useful context for error messages, but you cannot assume that the node is the only aggregate function.

Definition at line 2928 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getAgg().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateModality().

2928  {
2929  SqlNode node = select.getGroup();
2930  if (node != null) {
2931  return node;
2932  }
2933  node = select.getHaving();
2934  if (node != null) {
2935  return node;
2936  }
2937  return getAgg(select);
2938  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlValidatorCatalogReader org.apache.calcite.sql.validate.SqlValidatorImpl.getCatalogReader ( )
inline

Definition at line 334 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.catalogReader.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeTypeIfKnown(), and org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints().

334  {
335  return catalogReader;
336  }

+ Here is the caller graph for this function:

SqlConformance org.apache.calcite.sql.validate.SqlValidatorImpl.getConformance ( )
inline

Definition at line 330 of file SqlValidatorImpl.java.

330  {
331  return config.sqlConformance();
332  }
SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getCursorScope ( SqlSelect  select)
inline

Definition at line 1108 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.CURSOR.

1108  {
1109  return clauseScopes.get(IdPair.of(select, Clause.CURSOR));
1110  }
SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getEmptyScope ( )
inline

Definition at line 1104 of file SqlValidatorImpl.java.

1104  {
1105  return new EmptyScope(this);
1106  }
List<String> org.apache.calcite.sql.validate.SqlValidatorImpl.getFieldOrigin ( SqlNode  sqlQuery,
int  i 
)
inlineprivate

Definition at line 5564 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getRawSelectScope(), and setup.name.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.getFieldOrigins().

5564  {
5565  if (sqlQuery instanceof SqlSelect) {
5566  SqlSelect sqlSelect = (SqlSelect) sqlQuery;
5567  final SelectScope scope = getRawSelectScope(sqlSelect);
5568  final List<SqlNode> selectList = scope.getExpandedSelectList();
5569  final SqlNode selectItem = stripAs(selectList.get(i));
5570  if (selectItem instanceof SqlIdentifier) {
5571  final SqlQualified qualified =
5572  scope.fullyQualify((SqlIdentifier) selectItem);
5573  SqlValidatorNamespace namespace = qualified.namespace;
5574  final SqlValidatorTable table = namespace.getTable();
5575  if (table == null) {
5576  return null;
5577  }
5578  final List<String> origin =
5579  new ArrayList<>(table.getQualifiedName());
5580  for (String name : qualified.suffix()) {
5581  namespace = namespace.lookupChild(name);
5582  if (namespace == null) {
5583  return null;
5584  }
5585  origin.add(name);
5586  }
5587  return origin;
5588  }
5589  return null;
5590  } else if (sqlQuery instanceof SqlOrderBy) {
5591  return getFieldOrigin(((SqlOrderBy) sqlQuery).query, i);
5592  } else {
5593  return null;
5594  }
5595  }
List< String > getFieldOrigin(SqlNode sqlQuery, int i)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

List<List<String> > org.apache.calcite.sql.validate.SqlValidatorImpl.getFieldOrigins ( SqlNode  sqlQuery)
inline

Definition at line 5548 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getFieldOrigin(), and org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType().

5548  {
5549  if (sqlQuery instanceof SqlExplain) {
5550  return Collections.emptyList();
5551  }
5552  final RelDataType rowType = getValidatedNodeType(sqlQuery);
5553  final int fieldCount = rowType.getFieldCount();
5554  if (!sqlQuery.isA(SqlKind.QUERY)) {
5555  return Collections.nCopies(fieldCount, null);
5556  }
5557  final List<List<String>> list = new ArrayList<>();
5558  for (int i = 0; i < fieldCount; i++) {
5559  list.add(getFieldOrigin(sqlQuery, i));
5560  }
5561  return ImmutableNullableList.copyOf(list);
5562  }
List< String > getFieldOrigin(SqlNode sqlQuery, int i)

+ Here is the call graph for this function:

SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getFromScope ( SqlSelect  select)
inline

Definition at line 1138 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateWindowClause().

1138  {
1139  return scopes.get(select);
1140  }

+ Here is the caller graph for this function:

SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getGroupScope ( SqlSelect  select)
inline

Definition at line 1133 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.GROUP_BY.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInGroupBy(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateGroupByItem(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateGroupClause().

1133  {
1134  // Yes, it's the same as getWhereScope
1135  return clauseScopes.get(IdPair.of(select, Clause.GROUP_BY));
1136  }

+ Here is the caller graph for this function:

SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getHavingScope ( SqlSelect  select)
inline

Definition at line 1128 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.SELECT.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

1128  {
1129  // Yes, it's the same as getSelectScope
1130  return clauseScopes.get(IdPair.of(select, Clause.SELECT));
1131  }

+ Here is the caller graph for this function:

SqlSelect org.apache.calcite.sql.validate.SqlValidatorImpl.getInnerSelect ( SqlNode  node)
inlineprivate

Definition at line 1434 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites().

1434  {
1435  for (;;) {
1436  if (node instanceof SqlSelect) {
1437  return (SqlSelect) node;
1438  } else if (node instanceof SqlOrderBy) {
1439  node = ((SqlOrderBy) node).query;
1440  } else if (node instanceof SqlWith) {
1441  node = ((SqlWith) node).body;
1442  } else {
1443  return null;
1444  }
1445  }
1446  }

+ Here is the caller graph for this function:

SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getJoinScope ( SqlNode  node)
inline

Definition at line 1150 of file SqlValidatorImpl.java.

1150  {
1151  return scopes.get(stripAs(node));
1152  }
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getLogicalSourceRowType ( RelDataType  sourceRowType,
SqlInsert  insert 
)
inlineprotected

Definition at line 4625 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.getLogicalTargetRowType(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert().

4627  {
4628  return sourceRowType;
4629  }

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getLogicalTargetRowType ( RelDataType  targetRowType,
SqlInsert  insert 
)
inlineprotected

Definition at line 4601 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getLogicalSourceRowType(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert().

4603  {
4604  if (insert.getTargetColumnList() == null
4605  && this.config.sqlConformance().isInsertSubsetColumnsAllowed()) {
4606  // Target an implicit subset of columns.
4607  final SqlNode source = insert.getSource();
4608  final RelDataType sourceRowType = getNamespace(source).getRowType();
4609  final RelDataType logicalSourceRowType =
4610  getLogicalSourceRowType(sourceRowType, insert);
4611  final RelDataType implicitTargetRowType =
4612  typeFactory.createStructType(
4613  targetRowType.getFieldList()
4614  .subList(0, logicalSourceRowType.getFieldCount()));
4615  final SqlValidatorNamespace targetNamespace = getNamespace(insert);
4616  validateNamespace(targetNamespace, implicitTargetRowType);
4617  return implicitTargetRowType;
4618  } else {
4619  // Either the set of columns are explicitly targeted, or target the full
4620  // set of columns.
4621  return targetRowType;
4622  }
4623  }
void validateNamespace(final SqlValidatorNamespace namespace, RelDataType targetRowType)
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
RelDataType getLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getMatchRecognizeScope ( SqlMatchRecognize  node)
inline

Definition at line 1146 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateMatchRecognize().

1146  {
1147  return scopes.get(node);
1148  }

+ Here is the caller graph for this function:

SqlValidatorNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace ( SqlNode  node,
SqlValidatorScope  scope 
)
inlineprivate

Definition at line 1158 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInUsing(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), org.apache.calcite.sql.validate.SqlValidatorImpl.getLogicalTargetRowType(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeTypeIfKnown(), org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.lookupHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.OrderExpressionExpander(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateDelete(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateInsert(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMatchRecognize(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMerge(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateUpdate(), and org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.visit().

1159  {
1160  if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) {
1161  final SqlIdentifier id = (SqlIdentifier) node;
1162  final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent();
1163  return getNamespace(id, idScope);
1164  } else if (node instanceof SqlCall) {
1165  // Handle extended identifiers.
1166  final SqlCall call = (SqlCall) node;
1167  switch (call.getOperator().getKind()) {
1168  case TABLE_REF:
1169  return getNamespace(call.operand(0), scope);
1170  case EXTEND:
1171  final SqlNode operand0 = call.getOperandList().get(0);
1172  final SqlIdentifier identifier = operand0.getKind() == SqlKind.TABLE_REF
1173  ? ((SqlCall) operand0).operand(0)
1174  : (SqlIdentifier) operand0;
1175  final DelegatingScope idScope = (DelegatingScope) scope;
1176  return getNamespace(identifier, idScope);
1177  case AS:
1178  final SqlNode nested = call.getOperandList().get(0);
1179  switch (nested.getKind()) {
1180  case TABLE_REF:
1181  case EXTEND:
1182  return getNamespace(nested, scope);
1183  }
1184  break;
1185  }
1186  }
1187  return getNamespace(node);
1188  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)

+ Here is the caller graph for this function:

SqlValidatorNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace ( SqlIdentifier  id,
DelegatingScope  scope 
)
inlineprivate

Definition at line 1190 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace().

1190  {
1191  if (id.isSimple()) {
1192  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
1193  final SqlValidatorScope.ResolvedImpl resolved =
1194  new SqlValidatorScope.ResolvedImpl();
1195  scope.resolve(id.names, nameMatcher, false, resolved);
1196  if (resolved.count() == 1) {
1197  return resolved.only().namespace;
1198  }
1199  }
1200  return getNamespace(id);
1201  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)

+ Here is the call graph for this function:

SqlValidatorNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace ( SqlNode  node)
inline

Definition at line 1203 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace().

1203  {
1204  switch (node.getKind()) {
1205  case AS:
1206 
1207  // AS has a namespace if it has a column list 'AS t (c1, c2, ...)'
1208  final SqlValidatorNamespace ns = namespaces.get(node);
1209  if (ns != null) {
1210  return ns;
1211  }
1212  // fall through
1213  case TABLE_REF:
1214  case SNAPSHOT:
1215  case OVER:
1216  case COLLECTION_TABLE:
1217  case ORDER_BY:
1218  case TABLESAMPLE:
1219  return getNamespace(((SqlCall) node).operand(0));
1220  default:
1221  return namespaces.get(node);
1222  }
1223  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)

+ Here is the call graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.getNthExpr ( SqlNode  query,
int  ordinal,
int  sourceCount 
)
inlineprivate

Locates the n'th expression in an INSERT or UPDATE query.

Parameters
queryQuery
ordinalOrdinal of expression
sourceCountNumber of expressions
Returns
Ordinal'th expression, never null

Definition at line 4723 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkTypeAssignment().

4723  {
4724  if (query instanceof SqlInsert) {
4725  SqlInsert insert = (SqlInsert) query;
4726  if (insert.getTargetColumnList() != null) {
4727  return insert.getTargetColumnList().get(ordinal);
4728  } else {
4729  return getNthExpr(
4730  insert.getSource(),
4731  ordinal,
4732  sourceCount);
4733  }
4734  } else if (query instanceof SqlUpdate) {
4735  SqlUpdate update = (SqlUpdate) query;
4736  if (update.getSourceExpressionList() != null) {
4737  return update.getSourceExpressionList().get(ordinal);
4738  } else {
4739  return getNthExpr(
4740  update.getSourceSelect(),
4741  ordinal,
4742  sourceCount);
4743  }
4744  } else if (query instanceof SqlSelect) {
4745  SqlSelect select = (SqlSelect) query;
4746  if (select.getSelectList().size() == sourceCount) {
4747  return select.getSelectList().get(ordinal);
4748  } else {
4749  return query; // give up
4750  }
4751  } else {
4752  return query; // give up
4753  }
4754  }
SqlNode getNthExpr(SqlNode query, int ordinal, int sourceCount)

+ Here is the caller graph for this function:

SqlOperatorTable org.apache.calcite.sql.validate.SqlValidatorImpl.getOperatorTable ( )
inline

Definition at line 338 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.opTab.

338  {
339  return opTab;
340  }
SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getOrderScope ( SqlSelect  select)
inline
SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.getOriginal ( SqlNode  expr)
inline

Definition at line 5078 of file SqlValidatorImpl.java.

5078  {
5079  SqlNode original = originalExprs.get(expr);
5080  if (original == null) {
5081  original = expr;
5082  }
5083  return original;
5084  }
SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getOverScope ( SqlNode  node)
inline

Definition at line 1154 of file SqlValidatorImpl.java.

1154  {
1155  return scopes.get(node);
1156  }
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getParameterRowType ( SqlNode  sqlQuery)
inline

Definition at line 5597 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType(), and run_benchmark_import.type.

5597  {
5598  // NOTE: We assume that bind variables occur in depth-first tree
5599  // traversal in the same order that they occurred in the SQL text.
5600  final List<RelDataType> types = new ArrayList<>();
5601  // NOTE: but parameters on fetch/offset would be counted twice
5602  // as they are counted in the SqlOrderBy call and the inner SqlSelect call
5603  final Set<SqlNode> alreadyVisited = new HashSet<>();
5604  sqlQuery.accept(
5605  new SqlShuttle() {
5606 
5607  @Override public SqlNode visit(SqlDynamicParam param) {
5608  if (alreadyVisited.add(param)) {
5609  RelDataType type = getValidatedNodeType(param);
5610  types.add(type);
5611  }
5612  return param;
5613  }
5614  });
5615  return typeFactory.createStructType(
5616  types,
5617  new AbstractList<String>() {
5618  @Override public String get(int index) {
5619  return "?" + index;
5620  }
5621 
5622  @Override public int size() {
5623  return types.size();
5624  }
5625  });
5626  }

+ Here is the call graph for this function:

String org.apache.calcite.sql.validate.SqlValidatorImpl.getParentCursor ( String  columnListParamName)
inline

Definition at line 405 of file SqlValidatorImpl.java.

405  {
406  FunctionParamInfo funcParamInfo = functionCallStack.peek();
407  Map<String, String> parentCursorMap =
408  funcParamInfo.columnListParamToParentCursorMap;
409  return parentCursorMap.get(columnListParamName);
410  }
SelectScope org.apache.calcite.sql.validate.SqlValidatorImpl.getRawSelectScope ( SqlSelect  select)
inline

Definition at line 1120 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getSelectScope().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), org.apache.calcite.sql.validate.SqlValidatorImpl.getAgg(), org.apache.calcite.sql.validate.SqlValidatorImpl.getFieldOrigin(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateModality(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList().

1120  {
1121  SqlValidatorScope scope = getSelectScope(select);
1122  if (scope instanceof AggregatingSelectScope) {
1123  scope = ((AggregatingSelectScope) scope).getParent();
1124  }
1125  return (SelectScope) scope;
1126  }
SqlValidatorScope getSelectScope(SqlSelect select)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.getSelfJoinExprForUpdate ( SqlNode  table,
String  alias 
)
inlineprotected

Allows a subclass to provide information about how to convert an UPDATE into a MERGE via self-join. If this method returns null, then no such conversion takes place. Otherwise, this method should return a suitable unique identifier expression for the given table.

Parameters
tableidentifier for table being updated
aliasalias to use for qualifying columns in expression, or null for unqualified references; if this is equal to { UPDATE_SRC_ALIAS}, then column references have been anonymized to "SYS$ANONx", where x is the 1-based column number.
Returns
expression for unique identifier, or null to prevent conversion

Definition at line 1595 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(), and org.apache.calcite.sql.validate.SqlValidatorImpl.rewriteUpdateToMerge().

1597  {
1598  return null;
1599  }

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getTableConstructorRowType ( SqlCall  values,
SqlValidatorScope  scope 
)
inlinepackage

Returns null if there is no common type. E.g. if the rows have a different number of columns.

Definition at line 1655 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), report.rows, and run_benchmark_import.type.

1657  {
1658  final List<SqlNode> rows = values.getOperandList();
1659  assert rows.size() >= 1;
1660  final List<RelDataType> rowTypes = new ArrayList<>();
1661  for (final SqlNode row : rows) {
1662  assert row.getKind() == SqlKind.ROW;
1663  SqlCall rowConstructor = (SqlCall) row;
1664 
1665  // REVIEW jvs 10-Sept-2003: Once we support single-row queries as
1666  // rows, need to infer aliases from there.
1667  final List<String> aliasList = new ArrayList<>();
1668  final List<RelDataType> typeList = new ArrayList<>();
1669  for (Ord<SqlNode> column : Ord.zip(rowConstructor.getOperandList())) {
1670  final String alias = deriveAlias(column.e, column.i);
1671  aliasList.add(alias);
1672  final RelDataType type = deriveType(scope, column.e);
1673  typeList.add(type);
1674  }
1675  rowTypes.add(typeFactory.createStructType(typeList, aliasList));
1676  }
1677  if (rows.size() == 1) {
1678  // TODO jvs 10-Oct-2005: get rid of this workaround once
1679  // leastRestrictive can handle all cases
1680  return rowTypes.get(0);
1681  }
1682  return typeFactory.leastRestrictive(rowTypes);
1683  }
tuple rows
Definition: report.py:114
RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)

+ Here is the call graph for this function:

TypeCoercion org.apache.calcite.sql.validate.SqlValidatorImpl.getTypeCoercion ( )
inline

Definition at line 3910 of file SqlValidatorImpl.java.

3910  {
3911  assert config.typeCoercionEnabled();
3912  return this.typeCoercion;
3913  }
RelDataTypeFactory org.apache.calcite.sql.validate.SqlValidatorImpl.getTypeFactory ( )
inline

Definition at line 342 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

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

342  {
343  return typeFactory;
344  }

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getUnknownType ( )
inline
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType ( SqlNode  node)
inline

Definition at line 1685 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeTypeIfKnown(), and run_benchmark_import.type.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.getFieldOrigins(), org.apache.calcite.sql.validate.SqlValidatorImpl.getParameterRowType(), org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeTypeIfKnown(), org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.Permute(), org.apache.calcite.sql.validate.SqlValidatorImpl.usingNames(), org.apache.calcite.sql.validate.SqlValidatorImpl.validate(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateUpdate(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateWithItem().

1685  {
1686  RelDataType type = getValidatedNodeTypeIfKnown(node);
1687  if (type == null) {
1688  throw Util.needToImplement(node);
1689  } else {
1690  return type;
1691  }
1692  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeTypeIfKnown ( SqlNode  node)
inline

Definition at line 1694 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getCatalogReader(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType(), and run_benchmark_import.type.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), and org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType().

1694  {
1695  final RelDataType type = nodeToTypeMap.get(node);
1696  if (type != null) {
1697  return type;
1698  }
1699  final SqlValidatorNamespace ns = getNamespace(node);
1700  if (ns != null) {
1701  return ns.getType();
1702  }
1703  final SqlNode original = originalExprs.get(node);
1704  if (original != null && original != node) {
1705  return getValidatedNodeType(original);
1706  }
1707  if (node instanceof SqlIdentifier) {
1708  return getCatalogReader().getNamedType((SqlIdentifier) node);
1709  }
1710  return null;
1711  }
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ValidationErrorFunction org.apache.calcite.sql.validate.SqlValidatorImpl.getValidationErrorFunction ( )
inline

Definition at line 5028 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.validationErrorFunction.

5028  {
5029  return validationErrorFunction;
5030  }
final SqlValidatorImpl.ValidationErrorFunction validationErrorFunction
SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getWhereScope ( SqlSelect  select)
inline
SqlWindow org.apache.calcite.sql.validate.SqlValidatorImpl.getWindowByName ( SqlIdentifier  id,
SqlValidatorScope  scope 
)
inlineprotected

Definition at line 5039 of file SqlValidatorImpl.java.

References setup.name, and org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.resolveWindow(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateWindow().

5041  {
5042  SqlWindow window = null;
5043  if (id.isSimple()) {
5044  final String name = id.getSimple();
5045  window = scope.lookupWindow(name);
5046  }
5047  if (window == null) {
5048  throw newValidationError(id, RESOURCE.windowNotFound(id.toString()));
5049  }
5050  return window;
5051  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlWindow org.apache.calcite.sql.validate.SqlValidatorImpl.getWindowInOver ( SqlNode  over)
inlineprivate

Definition at line 3565 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp().

3565  {
3566  if (over.getKind() == SqlKind.OVER) {
3567  SqlNode window = ((SqlCall) over).getOperandList().get(1);
3568  if (window instanceof SqlWindow) {
3569  return (SqlWindow) window;
3570  }
3571  // SqlIdentifier, gets validated elsewhere
3572  return null;
3573  }
3574  return null;
3575  }

+ Here is the caller graph for this function:

SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getWithScope ( SqlNode  withItem)
inline

Definition at line 3905 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.scopes.

3905  {
3906  assert withItem.getKind() == SqlKind.WITH_ITEM;
3907  return scopes.get(withItem);
3908  }
final Map< SqlNode, SqlValidatorScope > scopes
void org.apache.calcite.sql.validate.SqlValidatorImpl.handleOffsetFetch ( SqlNode  offset,
SqlNode  fetch 
)
inlineprivate

Definition at line 1225 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.setValidatedNodeType(), and org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect().

1225  {
1226  if (offset instanceof SqlDynamicParam) {
1227  setValidatedNodeType(offset,
1228  typeFactory.createSqlType(SqlTypeName.INTEGER));
1229  }
1230  if (fetch instanceof SqlDynamicParam) {
1231  setValidatedNodeType(fetch,
1232  typeFactory.createSqlType(SqlTypeName.INTEGER));
1233  }
1234  }
final void setValidatedNodeType(SqlNode node, RelDataType type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.handleScalarSubQuery ( SqlSelect  parentSelect,
SqlSelect  selectItem,
List< SqlNode >  expandedSelectItems,
Set< String >  aliasList,
List< Map.Entry< String, RelDataType >>  fieldList 
)
inlineprivate

Processes SubQuery found in Select list. Checks that is actually Scalar sub-query and makes proper entries in each of the 3 lists used to create the final rowType entry.

Parameters
parentSelectbase SqlSelect item
selectItemchild SqlSelect from select list
expandedSelectItemsSelect items after processing
aliasListbuilt from user or system values
fieldListBuilt up entries for each select list entry

Definition at line 4270 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), org.apache.calcite.sql.validate.SqlValidatorImpl.getWhereScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), org.apache.calcite.sql.validate.SqlValidatorImpl.setValidatedNodeType(), and run_benchmark_import.type.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList().

4275  {
4276  // A scalar sub-query only has one output column.
4277  if (1 != selectItem.getSelectList().size()) {
4278  throw newValidationError(selectItem,
4279  RESOURCE.onlyScalarSubQueryAllowed());
4280  }
4281 
4282  // No expansion in this routine just append to list.
4283  expandedSelectItems.add(selectItem);
4284 
4285  // Get or generate alias and add to list.
4286  final String alias =
4287  deriveAlias(
4288  selectItem,
4289  aliasList.size());
4290  aliasList.add(alias);
4291 
4292  final SelectScope scope = (SelectScope) getWhereScope(parentSelect);
4293  final RelDataType type = deriveType(scope, selectItem);
4294  setValidatedNodeType(selectItem, type);
4295 
4296  // We do not want to pass on the RelRecordType returned
4297  // by the sub-query. Just the type of the single expression
4298  // in the sub-query select list.
4299  assert type instanceof RelRecordType;
4300  RelRecordType rec = (RelRecordType) type;
4301 
4302  RelDataType nodeType = rec.getFieldList().get(0).getType();
4303  nodeType = typeFactory.createTypeWithNullability(nodeType, true);
4304  fieldList.add(Pair.of(alias, nodeType));
4305  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
final void setValidatedNodeType(SqlNode node, RelDataType type)
RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
SqlValidatorScope getWhereScope(SqlSelect select)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CalciteException org.apache.calcite.sql.validate.SqlValidatorImpl.handleUnresolvedFunction ( SqlCall  call,
SqlFunction  unresolvedFunction,
List< RelDataType >  argTypes,
List< String >  argNames 
)
inline

Definition at line 1843 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.catalogReader, getMin(), and org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.deriveConstructorType(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall().

1845  {
1846  // For builtins, we can give a better error message
1847  final List<SqlOperator> overloads = new ArrayList<>();
1848  opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null,
1849  SqlSyntax.FUNCTION, overloads, catalogReader.nameMatcher());
1850  if (overloads.size() == 1) {
1851  SqlFunction fun = (SqlFunction) overloads.get(0);
1852  if ((fun.getSqlIdentifier() == null)
1853  && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) {
1854  final int expectedArgCount =
1855  fun.getOperandCountRange().getMin();
1856  throw newValidationError(call,
1857  RESOURCE.invalidArgCount(call.getOperator().getName(),
1858  expectedArgCount));
1859  }
1860  }
1861 
1862  AssignableOperandTypeChecker typeChecking =
1863  new AssignableOperandTypeChecker(argTypes, argNames);
1864  String signature =
1865  typeChecking.getAllowedSignatures(
1866  unresolvedFunction,
1867  unresolvedFunction.getName());
1868  throw newValidationError(call,
1869  RESOURCE.validatorUnknownFunction(signature));
1870  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
T getMin(const ExpressionRange &other)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.hasSortedPrefix ( SelectScope  scope,
SqlNodeList  orderList 
)
inlineprivate

Returns whether the prefix is sorted.

Definition at line 3778 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.isSortCompatible().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateModality().

3778  {
3779  return isSortCompatible(scope, orderList.get(0), false);
3780  }
boolean isSortCompatible(SelectScope scope, SqlNode node, boolean descending)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.inferUnknownTypes ( @Nonnull RelDataType  inferredType,
@Nonnull SqlValidatorScope  scope,
@Nonnull SqlNode  node 
)
inlineprotected

Definition at line 1872 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.booleanType, org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), org.apache.calcite.sql.validate.SqlValidatorImpl.setValidatedNodeType(), run_benchmark_import.type, and org.apache.calcite.sql.validate.SqlValidatorImpl.unknownType.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.expandOrderExpr(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandSelectItem(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateDefinitions(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateGroupClause(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateHavingClause(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMeasure(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelectList(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateValues(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateWhereOrOn().

1875  {
1876  Objects.requireNonNull(inferredType);
1877  Objects.requireNonNull(scope);
1878  Objects.requireNonNull(node);
1879  final SqlValidatorScope newScope = scopes.get(node);
1880  if (newScope != null) {
1881  scope = newScope;
1882  }
1883  boolean isNullLiteral = SqlUtil.isNullLiteral(node, false);
1884  if ((node instanceof SqlDynamicParam) || isNullLiteral) {
1885  if (inferredType.equals(unknownType)) {
1886  if (isNullLiteral) {
1887  if (config.typeCoercionEnabled()) {
1888  // derive type of null literal
1889  deriveType(scope, node);
1890  return;
1891  } else {
1892  throw newValidationError(node, RESOURCE.nullIllegal());
1893  }
1894  } else {
1895  throw newValidationError(node, RESOURCE.dynamicParamIllegal());
1896  }
1897  }
1898 
1899  // REVIEW: should dynamic parameter types always be nullable?
1900  RelDataType newInferredType =
1901  typeFactory.createTypeWithNullability(inferredType, true);
1902  if (SqlTypeUtil.inCharFamily(inferredType)) {
1903  newInferredType =
1904  typeFactory.createTypeWithCharsetAndCollation(
1905  newInferredType,
1906  inferredType.getCharset(),
1907  inferredType.getCollation());
1908  }
1909  setValidatedNodeType(node, newInferredType);
1910  } else if (node instanceof SqlNodeList) {
1911  SqlNodeList nodeList = (SqlNodeList) node;
1912  if (inferredType.isStruct()) {
1913  if (inferredType.getFieldCount() != nodeList.size()) {
1914  // this can happen when we're validating an INSERT
1915  // where the source and target degrees are different;
1916  // bust out, and the error will be detected higher up
1917  return;
1918  }
1919  }
1920  int i = 0;
1921  for (SqlNode child : nodeList) {
1922  RelDataType type;
1923  if (inferredType.isStruct()) {
1924  type = inferredType.getFieldList().get(i).getType();
1925  ++i;
1926  } else {
1927  type = inferredType;
1928  }
1929  inferUnknownTypes(type, scope, child);
1930  }
1931  } else if (node instanceof SqlCase) {
1932  final SqlCase caseCall = (SqlCase) node;
1933 
1934  final RelDataType whenType =
1935  caseCall.getValueOperand() == null ? booleanType : unknownType;
1936  for (SqlNode sqlNode : caseCall.getWhenOperands().getList()) {
1937  inferUnknownTypes(whenType, scope, sqlNode);
1938  }
1939  RelDataType returnType = deriveType(scope, node);
1940  for (SqlNode sqlNode : caseCall.getThenOperands().getList()) {
1941  inferUnknownTypes(returnType, scope, sqlNode);
1942  }
1943 
1944  if (!SqlUtil.isNullLiteral(caseCall.getElseOperand(), false)) {
1946  returnType,
1947  scope,
1948  caseCall.getElseOperand());
1949  } else {
1950  setValidatedNodeType(caseCall.getElseOperand(), returnType);
1951  }
1952  } else if (node.getKind() == SqlKind.AS) {
1953  // For AS operator, only infer the operand not the alias
1954  inferUnknownTypes(inferredType, scope, ((SqlCall) node).operand(0));
1955  } else if (node instanceof SqlCall) {
1956  final SqlCall call = (SqlCall) node;
1957  final SqlOperandTypeInference operandTypeInference =
1958  call.getOperator().getOperandTypeInference();
1959  final SqlCallBinding callBinding = new SqlCallBinding(this, scope, call);
1960  final List<SqlNode> operands = callBinding.operands();
1961  final RelDataType[] operandTypes = new RelDataType[operands.size()];
1962  Arrays.fill(operandTypes, unknownType);
1963  // TODO: eventually should assert(operandTypeInference != null)
1964  // instead; for now just eat it
1965  if (operandTypeInference != null) {
1966  operandTypeInference.inferOperandTypes(
1967  callBinding,
1968  inferredType,
1969  operandTypes);
1970  }
1971  for (int i = 0; i < operands.size(); ++i) {
1972  final SqlNode operand = operands.get(i);
1973  if (operand != null) {
1974  inferUnknownTypes(operandTypes[i], scope, operand);
1975  }
1976  }
1977  }
1978  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
final void setValidatedNodeType(SqlNode node, RelDataType type)
RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
void inferUnknownTypes(@Nonnull RelDataType inferredType,@Nonnull SqlValidatorScope scope,@Nonnull SqlNode node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate ( SqlSelect  select)
inline

Definition at line 2894 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getAggregate(), org.apache.calcite.sql.validate.SqlValidatorImpl.isNestedAggregateWindow(), org.apache.calcite.sql.validate.SqlValidatorImpl.isOverAggregateWindow(), and org.apache.calcite.sql.validate.SqlValidatorImpl.overFinder.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), and org.apache.calcite.sql.validate.SqlValidatorImpl.ExtendedExpander.visit().

2894  {
2895  if (getAggregate(select) != null) {
2896  return true;
2897  }
2898  // Also when nested window aggregates are present
2899  for (SqlCall call : overFinder.findAll(select.getSelectList())) {
2900  assert call.getKind() == SqlKind.OVER;
2901  if (isNestedAggregateWindow(call.operand(0))) {
2902  return true;
2903  }
2904  if (isOverAggregateWindow(call.operand(1))) {
2905  return true;
2906  }
2907  }
2908  return false;
2909  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate ( SqlNode  selectNode)
inline

Definition at line 2954 of file SqlValidatorImpl.java.

2954  {
2955  return aggFinder.findAgg(selectNode) != null;
2956  }
static boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregation ( SqlKind  kind)
inlinestaticprivate

Definition at line 5643 of file SqlValidatorImpl.java.

References MIN.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), org.apache.calcite.sql.validate.SqlValidatorImpl.isSingleVarRequired(), org.apache.calcite.sql.validate.SqlValidatorImpl.NavigationReplacer.visit(), and org.apache.calcite.sql.validate.SqlValidatorImpl.PatternValidator.visit().

5643  {
5644  return kind == SqlKind.SUM || kind == SqlKind.SUM0
5645  || kind == SqlKind.AVG || kind == SqlKind.COUNT
5646  || kind == SqlKind.MAX || kind == SqlKind.MIN;
5647  }

+ Here is the caller graph for this function:

static boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isLogicalNavigation ( SqlKind  kind)
inlinestaticprivate

Definition at line 5639 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isSingleVarRequired(), org.apache.calcite.sql.validate.SqlValidatorImpl.NavigationExpander.visit(), org.apache.calcite.sql.validate.SqlValidatorImpl.NavigationReplacer.visit(), and org.apache.calcite.sql.validate.SqlValidatorImpl.PatternValidator.visit().

5639  {
5640  return kind == SqlKind.FIRST || kind == SqlKind.LAST;
5641  }

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isNestedAggregateWindow ( SqlNode  node)
inlineprotected

Definition at line 2911 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.aggFinder, org.apache.calcite.sql.validate.SqlValidatorImpl.catalogReader, and org.apache.calcite.sql.validate.SqlValidatorImpl.opTab.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate().

2911  {
2912  AggFinder nestedAggFinder =
2913  new AggFinder(opTab, false, false, false, aggFinder,
2914  catalogReader.nameMatcher());
2915  return nestedAggFinder.findAgg(node) != null;
2916  }

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isOverAggregateWindow ( SqlNode  node)
inlineprotected

Definition at line 2918 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate().

2918  {
2919  return aggFinder.findAgg(node) != null;
2920  }

+ Here is the caller graph for this function:

static boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isPhysicalNavigation ( SqlKind  kind)
inlinestaticprivate

Definition at line 5635 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isSingleVarRequired(), org.apache.calcite.sql.validate.SqlValidatorImpl.NavigationExpander.visit(), and org.apache.calcite.sql.validate.SqlValidatorImpl.PatternValidator.visit().

5635  {
5636  return kind == SqlKind.PREV || kind == SqlKind.NEXT;
5637  }

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumn ( SqlIdentifier  identifier,
SqlValidatorScope  scope 
)
inlineprivate

Definition at line 3625 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.findTableColumnPair().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), and org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar().

3625  {
3626  Pair<String, String> pair = findTableColumnPair(identifier, scope);
3627 
3628  if (pair == null) {
3629  return false;
3630  }
3631 
3632  String columnName = pair.right;
3633 
3634  SqlValidatorTable sqlValidatorTable =
3635  scope.fullyQualify(identifier).namespace.getTable();
3636  if (sqlValidatorTable != null) {
3637  Table table = sqlValidatorTable.unwrap(Table.class);
3638  return table.isRolledUp(columnName);
3639  }
3640  return false;
3641  }
Pair< String, String > findTableColumnPair(SqlIdentifier identifier, SqlValidatorScope scope)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isRolledUpColumnAllowedInAgg ( SqlIdentifier  identifier,
SqlValidatorScope  scope,
SqlCall  aggCall,
SqlNode  parent 
)
inlineprivate

Definition at line 3603 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.findTableColumnPair().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp().

3604  {
3605  Pair<String, String> pair = findTableColumnPair(identifier, scope);
3606 
3607  if (pair == null) {
3608  return true;
3609  }
3610 
3611  String columnName = pair.right;
3612 
3613  SqlValidatorTable sqlValidatorTable =
3614  scope.fullyQualify(identifier).namespace.getTable();
3615  if (sqlValidatorTable != null) {
3616  Table table = sqlValidatorTable.unwrap(Table.class);
3617  return table.rolledUpColumnValidInsideAgg(columnName, aggCall, parent,
3618  catalogReader.getConfig());
3619  }
3620  return true;
3621  }
Pair< String, String > findTableColumnPair(SqlIdentifier identifier, SqlValidatorScope scope)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isRowWithDefault ( SqlNode  operand,
int  column 
)
inlineprivate

Definition at line 4591 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.isValuesWithDefault().

4591  {
4592  switch (operand.getKind()) {
4593  case ROW:
4594  final SqlCall row = (SqlCall) operand;
4595  return row.getOperandList().size() >= column
4596  && row.getOperandList().get(column).getKind() == SqlKind.DEFAULT;
4597  }
4598  return false;
4599  }

+ Here is the caller graph for this function:

static boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isRunningOrFinal ( SqlKind  kind)
inlinestaticprivate

Definition at line 5649 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.navigationInMeasure(), org.apache.calcite.sql.validate.SqlValidatorImpl.NavigationReplacer.visit(), and org.apache.calcite.sql.validate.SqlValidatorImpl.PatternValidator.visit().

5649  {
5650  return kind == SqlKind.RUNNING || kind == SqlKind.FINAL;
5651  }

+ Here is the caller graph for this function:

static boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isSingleVarRequired ( SqlKind  kind)
inlinestaticprivate

Definition at line 5653 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregation(), org.apache.calcite.sql.validate.SqlValidatorImpl.isLogicalNavigation(), and org.apache.calcite.sql.validate.SqlValidatorImpl.isPhysicalNavigation().

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

5653  {
5654  return isPhysicalNavigation(kind)
5655  || isLogicalNavigation(kind)
5656  || isAggregation(kind);
5657  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isSortCompatible ( SelectScope  scope,
SqlNode  node,
boolean  descending 
)
inlineprivate

Definition at line 3782 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.hasSortedPrefix().

3783  {
3784  switch (node.getKind()) {
3785  case DESCENDING:
3786  return isSortCompatible(scope, ((SqlCall) node).getOperandList().get(0),
3787  true);
3788  }
3789  final SqlMonotonicity monotonicity = scope.getMonotonicity(node);
3790  switch (monotonicity) {
3791  case INCREASING:
3792  case STRICTLY_INCREASING:
3793  return !descending;
3794  case DECREASING:
3795  case STRICTLY_DECREASING:
3796  return descending;
3797  default:
3798  return false;
3799  }
3800  }
boolean isSortCompatible(SelectScope scope, SqlNode node, boolean descending)

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isSystemField ( RelDataTypeField  field)
inline

Definition at line 5544 of file SqlValidatorImpl.java.

5544  {
5545  return false;
5546  }
boolean org.apache.calcite.sql.validate.SqlValidatorImpl.isValuesWithDefault ( SqlNode  source,
int  column 
)
inlineprivate

Returns whether a query uses

to populate a given column.

Definition at line 4578 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.isRowWithDefault().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.checkFieldCount().

4578  {
4579  switch (source.getKind()) {
4580  case VALUES:
4581  for (SqlNode operand : ((SqlCall) source).getOperandList()) {
4582  if (!isRowWithDefault(operand, column)) {
4583  return false;
4584  }
4585  }
4586  return true;
4587  }
4588  return false;
4589  }
boolean isRowWithDefault(SqlNode operand, int column)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlValidatorNamespace org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFieldNamespace ( RelDataType  rowType,
String  name 
)
inlinepackage

Definition at line 5091 of file SqlValidatorImpl.java.

References field(), and setup.name.

5091  {
5092  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
5093  final RelDataTypeField field = nameMatcher.field(rowType, name);
5094  if (field == null) {
5095  return null;
5096  }
5097  return new FieldNamespace(this, field.getType());
5098  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints ( SqlNode  node,
SqlValidatorScope  scope,
SqlParserPos  pos,
Collection< SqlMoniker >  hintList 
)
inlineprivate

Definition at line 828 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getCatalogReader(), org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.lookupJoinHints(), and org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupJoinHints(), and org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints().

832  {
833  if (node == null) {
834  // This can happen in cases like "select * _suggest_", so from clause is absent
835  return;
836  }
837  final SqlValidatorNamespace ns = getNamespace(node);
838  if (ns.isWrapperFor(IdentifierNamespace.class)) {
839  IdentifierNamespace idNs = ns.unwrap(IdentifierNamespace.class);
840  final SqlIdentifier id = idNs.getId();
841  for (int i = 0; i < id.names.size(); i++) {
842  if (pos.toString().equals(
843  id.getComponent(i).getParserPosition().toString())) {
844  final List<SqlMoniker> objNames = new ArrayList<>();
845  SqlValidatorUtil.getSchemaObjectMonikers(
847  id.names.subList(0, i + 1),
848  objNames);
849  for (SqlMoniker objName : objNames) {
850  if (objName.getType() != SqlMonikerType.FUNCTION) {
851  hintList.add(objName);
852  }
853  }
854  return;
855  }
856  }
857  }
858  switch (node.getKind()) {
859  case JOIN:
860  lookupJoinHints((SqlJoin) node, scope, pos, hintList);
861  break;
862  default:
863  lookupSelectHints(ns, pos, hintList);
864  break;
865  }
866  }
void lookupJoinHints(SqlJoin join, SqlValidatorScope scope, SqlParserPos pos, Collection< SqlMoniker > hintList)
void lookupSelectHints(SqlSelect select, SqlParserPos pos, Collection< SqlMoniker > hintList)
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

List<SqlMoniker> org.apache.calcite.sql.validate.SqlValidatorImpl.lookupHints ( SqlNode  topNode,
SqlParserPos  pos 
)
inline

Definition at line 760 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites(), and org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery().

760  {
761  SqlValidatorScope scope = new EmptyScope(this);
762  SqlNode outermostNode = performUnconditionalRewrites(topNode, false);
763  cursorSet.add(outermostNode);
764  if (outermostNode.isA(SqlKind.TOP_LEVEL)) {
766  scope,
767  null,
768  outermostNode,
769  outermostNode,
770  null,
771  false);
772  }
773  final SqlValidatorNamespace ns = getNamespace(outermostNode);
774  if (ns == null) {
775  throw new AssertionError("Not a query: " + outermostNode);
776  }
777  Collection<SqlMoniker> hintList = Sets.newTreeSet(SqlMoniker.COMPARATOR);
778  lookupSelectHints(ns, pos, hintList);
779  return ImmutableList.copyOf(hintList);
780  }
void lookupSelectHints(SqlSelect select, SqlParserPos pos, Collection< SqlMoniker > hintList)
SqlValidatorNamespace getNamespace(SqlNode node, SqlValidatorScope scope)
void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
SqlNode performUnconditionalRewrites(SqlNode node, boolean underFrom)

+ Here is the call graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.lookupJoinHints ( SqlJoin  join,
SqlValidatorScope  scope,
SqlParserPos  pos,
Collection< SqlMoniker >  hintList 
)
inlineprivate

Definition at line 868 of file SqlValidatorImpl.java.

References join(), and org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints().

872  {
873  SqlNode left = join.getLeft();
874  SqlNode right = join.getRight();
875  SqlNode condition = join.getCondition();
876  lookupFromHints(left, scope, pos, hintList);
877  if (hintList.size() > 0) {
878  return;
879  }
880  lookupFromHints(right, scope, pos, hintList);
881  if (hintList.size() > 0) {
882  return;
883  }
884  final JoinConditionType conditionType = join.getConditionType();
885  final SqlValidatorScope joinScope = scopes.get(join);
886  switch (conditionType) {
887  case ON:
888  condition.findValidOptions(this, joinScope, pos, hintList);
889  return;
890  default:
891 
892  // No suggestions.
893  // Not supporting hints for other types such as 'Using' yet.
894  }
895  }
std::string join(T const &container, std::string const &delim)
void lookupFromHints(SqlNode node, SqlValidatorScope scope, SqlParserPos pos, Collection< SqlMoniker > hintList)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

final void org.apache.calcite.sql.validate.SqlValidatorImpl.lookupNameCompletionHints ( SqlValidatorScope  scope,
List< String >  names,
SqlParserPos  pos,
Collection< SqlMoniker >  hintList 
)
inline

Populates a list of all the valid alternatives for an identifier.

Parameters
scopeValidation scope
namesComponents of the identifier
posposition
hintLista list of valid options

Definition at line 905 of file SqlValidatorImpl.java.

References field(), org.apache.calcite.sql.validate.SqlValidatorImpl.findAllValidFunctionNames(), org.apache.calcite.sql.validate.SqlValidatorImpl.findAllValidUdfNames(), and setup.name.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints().

909  {
910  // Remove the last part of name - it is a dummy
911  List<String> subNames = Util.skipLast(names);
912 
913  if (subNames.size() > 0) {
914  // If there's a prefix, resolve it to a namespace.
915  SqlValidatorNamespace ns = null;
916  for (String name : subNames) {
917  if (ns == null) {
918  final SqlValidatorScope.ResolvedImpl resolved =
919  new SqlValidatorScope.ResolvedImpl();
920  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
921  scope.resolve(ImmutableList.of(name), nameMatcher, false, resolved);
922  if (resolved.count() == 1) {
923  ns = resolved.only().namespace;
924  }
925  } else {
926  ns = ns.lookupChild(name);
927  }
928  if (ns == null) {
929  break;
930  }
931  }
932  if (ns != null) {
933  RelDataType rowType = ns.getRowType();
934  if (rowType.isStruct()) {
935  for (RelDataTypeField field : rowType.getFieldList()) {
936  hintList.add(
937  new SqlMonikerImpl(
938  field.getName(),
939  SqlMonikerType.COLUMN));
940  }
941  }
942  }
943 
944  // builtin function names are valid completion hints when the
945  // identifier has only 1 name part
946  findAllValidFunctionNames(names, this, hintList, pos);
947  } else {
948  // No prefix; use the children of the current scope (that is,
949  // the aliases in the FROM clause)
950  scope.findAliases(hintList);
951 
952  // If there's only one alias, add all child columns
953  SelectScope selectScope =
954  SqlValidatorUtil.getEnclosingSelectScope(scope);
955  if ((selectScope != null)
956  && (selectScope.getChildren().size() == 1)) {
957  RelDataType rowType =
958  selectScope.getChildren().get(0).getRowType();
959  for (RelDataTypeField field : rowType.getFieldList()) {
960  hintList.add(
961  new SqlMonikerImpl(
962  field.getName(),
963  SqlMonikerType.COLUMN));
964  }
965  }
966  }
967 
968  findAllValidUdfNames(names, this, hintList);
969  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
static void findAllValidUdfNames(List< String > names, SqlValidator validator, Collection< SqlMoniker > result)
static void findAllValidFunctionNames(List< String > names, SqlValidator validator, Collection< SqlMoniker > result, SqlParserPos pos)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlMoniker org.apache.calcite.sql.validate.SqlValidatorImpl.lookupQualifiedName ( SqlNode  topNode,
SqlParserPos  pos 
)
inline

Definition at line 782 of file SqlValidatorImpl.java.

782  {
783  final String posString = pos.toString();
784  IdInfo info = idPositions.get(posString);
785  if (info != null) {
786  final SqlQualified qualified = info.scope.fullyQualify(info.id);
787  return new SqlIdentifierMoniker(qualified.identifier);
788  } else {
789  return null;
790  }
791  }
void org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints ( SqlSelect  select,
SqlParserPos  pos,
Collection< SqlMoniker >  hintList 
)
inlinepackage

Looks up completion hints for a syntactically correct select SQL that has been parsed into an expression tree.

Parameters
selectthe Select node of the parsed expression tree
posindicates the position in the sql statement we want to get completion hints for
hintListlist of SqlMoniker (sql identifiers) that can fill in at the indicated position

Definition at line 803 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.getFromScope(), org.apache.calcite.sql.validate.SqlValidatorImpl.IdInfo.id, org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.lookupNameCompletionHints(), and org.apache.calcite.sql.validate.SqlValidatorImpl.IdInfo.scope.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupFromHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.lookupHints(), and org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints().

806  {
807  IdInfo info = idPositions.get(pos.toString());
808  if ((info == null) || (info.scope == null)) {
809  SqlNode fromNode = select.getFrom();
810  final SqlValidatorScope fromScope = getFromScope(select);
811  lookupFromHints(fromNode, fromScope, pos, hintList);
812  } else {
813  lookupNameCompletionHints(info.scope, info.id.names,
814  info.id.getParserPosition(), hintList);
815  }
816  }
final void lookupNameCompletionHints(SqlValidatorScope scope, List< String > names, SqlParserPos pos, Collection< SqlMoniker > hintList)
SqlValidatorScope getFromScope(SqlSelect select)
void lookupFromHints(SqlNode node, SqlValidatorScope scope, SqlParserPos pos, Collection< SqlMoniker > hintList)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints ( SqlValidatorNamespace  ns,
SqlParserPos  pos,
Collection< SqlMoniker >  hintList 
)
inlineprivate

Definition at line 818 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.lookupSelectHints().

821  {
822  final SqlNode node = ns.getNode();
823  if (node instanceof SqlSelect) {
824  lookupSelectHints((SqlSelect) node, pos, hintList);
825  }
826  }
void lookupSelectHints(SqlSelect select, SqlParserPos pos, Collection< SqlMoniker > hintList)

+ Here is the call graph for this function:

SqlCall org.apache.calcite.sql.validate.SqlValidatorImpl.makeNullaryCall ( SqlIdentifier  id)
inline

Definition at line 1737 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.findTableColumnPair(), and org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit().

1737  {
1738  if (id.names.size() == 1 && !id.isComponentQuoted(0)) {
1739  final List<SqlOperator> list = new ArrayList<>();
1740  opTab.lookupOperatorOverloads(id, null, SqlSyntax.FUNCTION, list,
1741  catalogReader.nameMatcher());
1742  for (SqlOperator operator : list) {
1743  if (operator.getSyntax() == SqlSyntax.FUNCTION_ID) {
1744  // Even though this looks like an identifier, it is a
1745  // actually a call to a function. Construct a fake
1746  // call to this function, so we can use the regular
1747  // operator validation.
1748  return new SqlBasicCall(operator, SqlNode.EMPTY_ARRAY,
1749  id.getParserPosition(), true, null);
1750  }
1751  }
1752  }
1753  return null;
1754  }

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.maybeCast ( SqlNode  node,
RelDataType  currentType,
RelDataType  desiredType 
)
inlineprivate

Definition at line 714 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.permute().

715  {
716  return SqlTypeUtil.equalSansNullability(typeFactory, currentType, desiredType)
717  ? node
718  : SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO,
719  node, SqlTypeUtil.convertTypeToSpec(desiredType));
720  }

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.navigationInDefine ( SqlNode  node,
String  alpha 
)
inlineprivate

Checks that all pattern variables within a function are the same, and canonizes expressions such as

PREV(B.price)

to

LAST(B.price, 0)

.

Definition at line 5391 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateDefinitions().

5391  {
5392  Set<String> prefix = node.accept(new PatternValidator(false));
5393  Util.discard(prefix);
5394  node = new NavigationExpander().go(node);
5395  node = new NavigationReplacer(alpha).go(node);
5396  return node;
5397  }

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.navigationInMeasure ( SqlNode  node,
boolean  allRows 
)
inlineprivate

Definition at line 5318 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.isRunningOrFinal().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.validateMeasure().

5318  {
5319  final Set<String> prefix = node.accept(new PatternValidator(true));
5320  Util.discard(prefix);
5321  final List<SqlNode> ops = ((SqlCall) node).getOperandList();
5322 
5323  final SqlOperator defaultOp =
5324  allRows ? SqlStdOperatorTable.RUNNING : SqlStdOperatorTable.FINAL;
5325  final SqlNode op0 = ops.get(0);
5326  if (!isRunningOrFinal(op0.getKind())
5327  || !allRows && op0.getKind() == SqlKind.RUNNING) {
5328  SqlNode newNode = defaultOp.createCall(SqlParserPos.ZERO, op0);
5329  node = SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO, newNode, ops.get(1));
5330  }
5331 
5332  node = new NavigationExpander().go(node);
5333  return node;
5334  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CalciteContextException org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError ( SqlNode  node,
Resources.ExInst< SqlValidatorException >  e 
)
inline

Definition at line 5032 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationErrorFunction.apply(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkFieldCount(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUp(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkRollUpInUsing(), org.apache.calcite.sql.validate.SqlValidatorImpl.checkTypeAssignment(), org.apache.calcite.sql.validate.SqlValidatorImpl.createTargetRowType(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveConstructorType(), org.apache.calcite.sql.validate.SqlValidatorImpl.expandStar(), org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationError.get(), org.apache.calcite.sql.validate.SqlValidatorImpl.getWindowByName(), org.apache.calcite.sql.validate.SqlValidatorImpl.handleScalarSubQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.handleUnresolvedFunction(), org.apache.calcite.sql.validate.SqlValidatorImpl.inferUnknownTypes(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.resolveWindow(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateAccess(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateAggregateParams(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateDefinitions(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateExpr(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateGroupClause(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateHavingClause(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateIntervalQualifier(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateJoin(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateLiteral(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateLiteralAsDouble(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateMatchRecognize(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateModality(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateNoAggs(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateOrderList(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSequenceValue(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateSnapshot(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateUsingCol(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateValues(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateWhereOrOn(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateWindowClause(), org.apache.calcite.sql.validate.SqlValidatorImpl.validateWithItem(), org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit(), org.apache.calcite.sql.validate.SqlValidatorImpl.OrderExpressionExpander.visit(), and org.apache.calcite.sql.validate.SqlValidatorImpl.PatternValidator.visit().

5033  {
5034  assert node != null;
5035  final SqlParserPos pos = node.getParserPosition();
5036  return SqlUtil.newContextException(pos, e);
5037  }

+ Here is the caller graph for this function:

SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.performUnconditionalRewrites ( SqlNode  node,
boolean  underFrom 
)
inlineprotected

Performs expression rewrites which are always used unconditionally. These rewrites massage the expression tree into a standard form so that the rest of the validation logic can be simpler.

Parameters
nodeexpression to be rewritten
underFromwhether node appears directly under a FROM clause
Returns
rewritten expression

Definition at line 1245 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.createSourceSelectForDelete(), org.apache.calcite.sql.validate.SqlValidatorImpl.createSourceSelectForUpdate(), org.apache.calcite.sql.validate.SqlValidatorImpl.getInnerSelect(), org.apache.calcite.sql.validate.SqlValidatorImpl.getSelfJoinExprForUpdate(), org.apache.calcite.sql.validate.SqlValidatorImpl.handleOffsetFetch(), org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate(), org.apache.calcite.sql.validate.SqlValidatorImpl.rewriteMerge(), org.apache.calcite.sql.validate.SqlValidatorImpl.rewriteUpdateToMerge(), org.apache.calcite.sql.validate.SqlValidatorImpl.UPDATE_SRC_ALIAS, and org.apache.calcite.sql.validate.SqlValidatorImpl.validatingSqlMerge.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupHints(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression().

1247  {
1248  if (node == null) {
1249  return null;
1250  }
1251 
1252  SqlNode newOperand;
1253 
1254  // first transform operands and invoke generic call rewrite
1255  if (node instanceof SqlCall) {
1256  if (node instanceof SqlMerge) {
1257  validatingSqlMerge = true;
1258  }
1259  SqlCall call = (SqlCall) node;
1260  final SqlKind kind = call.getKind();
1261  final List<SqlNode> operands = call.getOperandList();
1262  for (int i = 0; i < operands.size(); i++) {
1263  SqlNode operand = operands.get(i);
1264  boolean childUnderFrom;
1265  if (kind == SqlKind.SELECT) {
1266  childUnderFrom = i == SqlSelect.FROM_OPERAND;
1267  } else if (kind == SqlKind.AS && (i == 0)) {
1268  // for an aliased expression, it is under FROM if
1269  // the AS expression is under FROM
1270  childUnderFrom = underFrom;
1271  } else {
1272  childUnderFrom = false;
1273  }
1274  newOperand =
1275  performUnconditionalRewrites(operand, childUnderFrom);
1276  if (newOperand != null && newOperand != operand) {
1277  call.setOperand(i, newOperand);
1278  }
1279  }
1280 
1281  if (call.getOperator() instanceof SqlUnresolvedFunction) {
1282  assert call instanceof SqlBasicCall;
1283  final SqlUnresolvedFunction function =
1284  (SqlUnresolvedFunction) call.getOperator();
1285  // This function hasn't been resolved yet. Perform
1286  // a half-hearted resolution now in case it's a
1287  // builtin function requiring special casing. If it's
1288  // not, we'll handle it later during overload resolution.
1289  final List<SqlOperator> overloads = new ArrayList<>();
1290  opTab.lookupOperatorOverloads(function.getNameAsId(),
1291  function.getFunctionType(), SqlSyntax.FUNCTION, overloads,
1292  catalogReader.nameMatcher());
1293  if (overloads.size() == 1) {
1294  ((SqlBasicCall) call).setOperator(overloads.get(0));
1295  }
1296  }
1297  if (config.callRewrite()) {
1298  node = call.getOperator().rewriteCall(this, call);
1299  }
1300  } else if (node instanceof SqlNodeList) {
1301  SqlNodeList list = (SqlNodeList) node;
1302  for (int i = 0, count = list.size(); i < count; i++) {
1303  SqlNode operand = list.get(i);
1304  newOperand =
1306  operand,
1307  false);
1308  if (newOperand != null) {
1309  list.getList().set(i, newOperand);
1310  }
1311  }
1312  }
1313 
1314  // now transform node itself
1315  final SqlKind kind = node.getKind();
1316  switch (kind) {
1317  case VALUES:
1318  // CHECKSTYLE: IGNORE 1
1319  if (underFrom || true) {
1320  // leave FROM (VALUES(...)) [ AS alias ] clauses alone,
1321  // otherwise they grow cancerously if this rewrite is invoked
1322  // over and over
1323  return node;
1324  } else {
1325  final SqlNodeList selectList =
1326  new SqlNodeList(SqlParserPos.ZERO);
1327  selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
1328  return new SqlSelect(node.getParserPosition(), null, selectList, node,
1329  null, null, null, null, null, null, null, null);
1330  }
1331 
1332  case ORDER_BY: {
1333  SqlOrderBy orderBy = (SqlOrderBy) node;
1334  handleOffsetFetch(orderBy.offset, orderBy.fetch);
1335  if (orderBy.query instanceof SqlSelect) {
1336  SqlSelect select = (SqlSelect) orderBy.query;
1337 
1338  // Don't clobber existing ORDER BY. It may be needed for
1339  // an order-sensitive function like RANK.
1340  if (select.getOrderList() == null) {
1341  // push ORDER BY into existing select
1342  select.setOrderBy(orderBy.orderList);
1343  select.setOffset(orderBy.offset);
1344  select.setFetch(orderBy.fetch);
1345  return select;
1346  }
1347  }
1348  if (orderBy.query instanceof SqlWith
1349  && ((SqlWith) orderBy.query).body instanceof SqlSelect) {
1350  SqlWith with = (SqlWith) orderBy.query;
1351  SqlSelect select = (SqlSelect) with.body;
1352 
1353  // Don't clobber existing ORDER BY. It may be needed for
1354  // an order-sensitive function like RANK.
1355  if (select.getOrderList() == null) {
1356  // push ORDER BY into existing select
1357  select.setOrderBy(orderBy.orderList);
1358  select.setOffset(orderBy.offset);
1359  select.setFetch(orderBy.fetch);
1360  return with;
1361  }
1362  }
1363  final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
1364  selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
1365  final SqlNodeList orderList;
1366  if (getInnerSelect(node) != null && isAggregate(getInnerSelect(node))) {
1367  orderList = SqlNode.clone(orderBy.orderList);
1368  // We assume that ORDER BY item does not have ASC etc.
1369  // We assume that ORDER BY item is present in SELECT list.
1370  for (int i = 0; i < orderList.size(); i++) {
1371  SqlNode sqlNode = orderList.get(i);
1372  SqlNodeList selectList2 = getInnerSelect(node).getSelectList();
1373  for (Ord<SqlNode> sel : Ord.zip(selectList2)) {
1374  if (stripAs(sel.e).equalsDeep(sqlNode, Litmus.IGNORE)) {
1375  orderList.set(i,
1376  SqlLiteral.createExactNumeric(Integer.toString(sel.i + 1),
1377  SqlParserPos.ZERO));
1378  }
1379  }
1380  }
1381  } else {
1382  orderList = orderBy.orderList;
1383  }
1384  return new SqlSelect(SqlParserPos.ZERO, null, selectList, orderBy.query,
1385  null, null, null, null, orderList, orderBy.offset,
1386  orderBy.fetch, null);
1387  }
1388 
1389  case EXPLICIT_TABLE: {
1390  // (TABLE t) is equivalent to (SELECT * FROM t)
1391  SqlCall call = (SqlCall) node;
1392  final SqlNodeList selectList = new SqlNodeList(SqlParserPos.ZERO);
1393  selectList.add(SqlIdentifier.star(SqlParserPos.ZERO));
1394  return new SqlSelect(SqlParserPos.ZERO, null, selectList, call.operand(0),
1395  null, null, null, null, null, null, null, null);
1396  }
1397 
1398  case DELETE: {
1399  SqlDelete call = (SqlDelete) node;
1400  SqlSelect select = createSourceSelectForDelete(call);
1401  call.setSourceSelect(select);
1402  break;
1403  }
1404 
1405  case UPDATE: {
1406  SqlUpdate call = (SqlUpdate) node;
1407  SqlSelect select = createSourceSelectForUpdate(call);
1408  call.setSourceSelect(select);
1409 
1410  // See if we're supposed to rewrite UPDATE to MERGE
1411  // (unless this is the UPDATE clause of a MERGE,
1412  // in which case leave it alone).
1413  if (!validatingSqlMerge) {
1414  SqlNode selfJoinSrcExpr =
1416  call.getTargetTable(),
1418  if (selfJoinSrcExpr != null) {
1419  node = rewriteUpdateToMerge(call, selfJoinSrcExpr);
1420  }
1421  }
1422  break;
1423  }
1424 
1425  case MERGE: {
1426  SqlMerge call = (SqlMerge) node;
1427  rewriteMerge(call);
1428  break;
1429  }
1430  }
1431  return node;
1432  }
SqlNode rewriteUpdateToMerge(SqlUpdate updateCall, SqlNode selfJoinSrcExpr)
SqlNode getSelfJoinExprForUpdate(SqlNode table, String alias)
SqlNode performUnconditionalRewrites(SqlNode node, boolean underFrom)
void handleOffsetFetch(SqlNode offset, SqlNode fetch)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.popFunctionCall ( )
inline

Definition at line 400 of file SqlValidatorImpl.java.

400  {
401  functionCallStack.pop();
402  }
void org.apache.calcite.sql.validate.SqlValidatorImpl.pushFunctionCall ( )
inline

Definition at line 394 of file SqlValidatorImpl.java.

394  {
395  FunctionParamInfo funcInfo = new FunctionParamInfo();
396  functionCallStack.push(funcInfo);
397  }
SqlNode org.apache.calcite.sql.validate.SqlValidatorImpl.registerFrom ( SqlValidatorScope  parentScope,
SqlValidatorScope  usingScope,
boolean  register,
final SqlNode  node,
SqlNode  enclosingNode,
String  alias,
SqlNodeList  extendList,
boolean  forceNullable,
final boolean  lateral 
)
inlineprivate

Registers scopes and namespaces implied a relational expression in the FROM clause.

parentScope

and

usingScope

are often the same. They differ when the namespace are not visible within the parent. (Example needed.)

Likewise,

enclosingNode

and

node

are often the same.

enclosingNode

is the topmost node within the FROM clause, from which any decorations like an alias (AS alias) or a table sample clause are stripped away to get

node

. Both are recorded in the namespace.

Parameters
parentScopeParent scope which this scope turns to in order to resolve objects
usingScopeScope whose child list this scope should add itself to
registerWhether to register this scope as a child of
usingScope
nodeNode which namespace is based on
enclosingNodeOutermost node for namespace, including decorations such as alias and sample clause
aliasAlias
extendListDefinitions of extended columns
forceNullableWhether to force the type of namespace to be nullable because it is in an outer join
lateralWhether LATERAL is specified, so that items to the left of this in the JOIN tree are visible in the scope
Returns
registered node, usually the same as
node

Definition at line 2096 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias(), org.apache.calcite.sql.validate.SqlValidatorImpl.config(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.getSelectScope(), join(), LEFT, setup.name, org.apache.calcite.sql.validate.SqlValidatorImpl.nextGeneratedId, org.apache.calcite.sql.validate.SqlValidatorImpl.registerMatchRecognize(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerSubQueries(), org.apache.calcite.sql.validate.SqlValidatorImpl.shouldAllowOverRelation(), org.apache.calcite.sql.validate.SqlValidatorImpl.tableScope, toString(), and UNION.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.registerMatchRecognize(), and org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery().

2105  {
2106  final SqlKind kind = node.getKind();
2107 
2108  SqlNode expr;
2109  SqlNode newExpr;
2110 
2111  // Add an alias if necessary.
2112  SqlNode newNode = node;
2113  if (alias == null) {
2114  switch (kind) {
2115  case IDENTIFIER:
2116  case OVER:
2117  alias = deriveAlias(node, -1);
2118  if (alias == null) {
2119  alias = deriveAlias(node, nextGeneratedId++);
2120  }
2121  if (config.identifierExpansion()) {
2122  newNode = SqlValidatorUtil.addAlias(node, alias);
2123  }
2124  break;
2125 
2126  case SELECT:
2127  case UNION:
2128  case INTERSECT:
2129  case EXCEPT:
2130  case VALUES:
2131  case UNNEST:
2132  case OTHER_FUNCTION:
2133  case COLLECTION_TABLE:
2134  case MATCH_RECOGNIZE:
2135 
2136  // give this anonymous construct a name since later
2137  // query processing stages rely on it
2138  alias = deriveAlias(node, nextGeneratedId++);
2139  if (config.identifierExpansion()) {
2140  // Since we're expanding identifiers, we should make the
2141  // aliases explicit too, otherwise the expanded query
2142  // will not be consistent if we convert back to SQL, e.g.
2143  // "select EXPR$1.EXPR$2 from values (1)".
2144  newNode = SqlValidatorUtil.addAlias(node, alias);
2145  }
2146  break;
2147  }
2148  }
2149 
2150  if (lateral) {
2151  SqlValidatorScope s = usingScope;
2152  while (s instanceof JoinScope) {
2153  s = ((JoinScope) s).getUsingScope();
2154  }
2155  final SqlNode node2 = s != null ? s.getNode() : node;
2156  final TableScope tableScope = new TableScope(parentScope, node2);
2157  if (usingScope instanceof ListScope) {
2158  for (ScopeChild child : ((ListScope) usingScope).children) {
2159  tableScope.addChild(child.namespace, child.name, child.nullable);
2160  }
2161  }
2162  parentScope = tableScope;
2163  }
2164 
2165  SqlCall call;
2166  SqlNode operand;
2167  SqlNode newOperand;
2168 
2169  switch (kind) {
2170  case AS:
2171  call = (SqlCall) node;
2172  if (alias == null) {
2173  alias = call.operand(1).toString();
2174  }
2175  final boolean needAlias = call.operandCount() > 2;
2176  expr = call.operand(0);
2177  newExpr =
2178  registerFrom(
2179  parentScope,
2180  usingScope,
2181  !needAlias,
2182  expr,
2183  enclosingNode,
2184  alias,
2185  extendList,
2186  forceNullable,
2187  lateral);
2188  if (newExpr != expr) {
2189  call.setOperand(0, newExpr);
2190  }
2191 
2192  // If alias has a column list, introduce a namespace to translate
2193  // column names. We skipped registering it just now.
2194  if (needAlias) {
2196  usingScope,
2197  alias,
2198  new AliasNamespace(this, call, enclosingNode),
2199  forceNullable);
2200  }
2201  return node;
2202  case MATCH_RECOGNIZE:
2203  registerMatchRecognize(parentScope, usingScope,
2204  (SqlMatchRecognize) node, enclosingNode, alias, forceNullable);
2205  return node;
2206  case TABLESAMPLE:
2207  call = (SqlCall) node;
2208  expr = call.operand(0);
2209  newExpr =
2210  registerFrom(
2211  parentScope,
2212  usingScope,
2213  true,
2214  expr,
2215  enclosingNode,
2216  alias,
2217  extendList,
2218  forceNullable,
2219  lateral);
2220  if (newExpr != expr) {
2221  call.setOperand(0, newExpr);
2222  }
2223  return node;
2224 
2225  case JOIN:
2226  final SqlJoin join = (SqlJoin) node;
2227  final JoinScope joinScope =
2228  new JoinScope(parentScope, usingScope, join);
2229  scopes.put(join, joinScope);
2230  final SqlNode left = join.getLeft();
2231  final SqlNode right = join.getRight();
2232  boolean forceLeftNullable = forceNullable;
2233  boolean forceRightNullable = forceNullable;
2234  switch (join.getJoinType()) {
2235  case LEFT:
2236  forceRightNullable = true;
2237  break;
2238  case RIGHT:
2239  forceLeftNullable = true;
2240  break;
2241  case FULL:
2242  forceLeftNullable = true;
2243  forceRightNullable = true;
2244  break;
2245  }
2246  final SqlNode newLeft =
2247  registerFrom(
2248  parentScope,
2249  joinScope,
2250  true,
2251  left,
2252  left,
2253  null,
2254  null,
2255  forceLeftNullable,
2256  lateral);
2257  if (newLeft != left) {
2258  join.setLeft(newLeft);
2259  }
2260  final SqlNode newRight =
2261  registerFrom(
2262  parentScope,
2263  joinScope,
2264  true,
2265  right,
2266  right,
2267  null,
2268  null,
2269  forceRightNullable,
2270  lateral);
2271  if (newRight != right) {
2272  join.setRight(newRight);
2273  }
2274  registerSubQueries(joinScope, join.getCondition());
2275  final JoinNamespace joinNamespace = new JoinNamespace(this, join);
2276  registerNamespace(null, null, joinNamespace, forceNullable);
2277  return join;
2278 
2279  case IDENTIFIER:
2280  final SqlIdentifier id = (SqlIdentifier) node;
2281  final IdentifierNamespace newNs =
2282  new IdentifierNamespace(
2283  this, id, extendList, enclosingNode,
2284  parentScope);
2285  registerNamespace(register ? usingScope : null, alias, newNs,
2286  forceNullable);
2287  if (tableScope == null) {
2288  tableScope = new TableScope(parentScope, node);
2289  }
2290  tableScope.addChild(newNs, alias, forceNullable);
2291  if (extendList != null && extendList.size() != 0) {
2292  return enclosingNode;
2293  }
2294  return newNode;
2295 
2296  case LATERAL:
2297  return registerFrom(
2298  parentScope,
2299  usingScope,
2300  register,
2301  ((SqlCall) node).operand(0),
2302  enclosingNode,
2303  alias,
2304  extendList,
2305  forceNullable,
2306  true);
2307 
2308  case COLLECTION_TABLE:
2309  call = (SqlCall) node;
2310  operand = call.operand(0);
2311  newOperand =
2312  registerFrom(
2313  parentScope,
2314  usingScope,
2315  register,
2316  operand,
2317  enclosingNode,
2318  alias,
2319  extendList,
2320  forceNullable, lateral);
2321  if (newOperand != operand) {
2322  call.setOperand(0, newOperand);
2323  }
2324  // If the operator is SqlWindowTableFunction, restricts the scope as
2325  // its first operand's (the table) scope.
2326  if (operand instanceof SqlBasicCall) {
2327  final SqlBasicCall call1 = (SqlBasicCall) operand;
2328  final SqlOperator op = call1.getOperator();
2329  if (op instanceof SqlWindowTableFunction
2330  && call1.operand(0).getKind() == SqlKind.SELECT) {
2331  scopes.put(node, getSelectScope(call1.operand(0)));
2332  return newNode;
2333  }
2334  }
2335  // Put the usingScope which can be a JoinScope
2336  // or a SelectScope, in order to see the left items
2337  // of the JOIN tree.
2338  scopes.put(node, usingScope);
2339  return newNode;
2340 
2341  case UNNEST:
2342  if (!lateral) {
2343  return registerFrom(parentScope, usingScope, register, node,
2344  enclosingNode, alias, extendList, forceNullable, true);
2345  }
2346  // fall through
2347  case SELECT:
2348  case UNION:
2349  case INTERSECT:
2350  case EXCEPT:
2351  case VALUES:
2352  case WITH:
2353  case OTHER_FUNCTION:
2354  if (alias == null) {
2355  alias = deriveAlias(node, nextGeneratedId++);
2356  }
2357  registerQuery(
2358  parentScope,
2359  register ? usingScope : null,
2360  node,
2361  enclosingNode,
2362  alias,
2363  forceNullable);
2364  return newNode;
2365 
2366  case OVER:
2367  if (!shouldAllowOverRelation()) {
2368  throw Util.unexpected(kind);
2369  }
2370  call = (SqlCall) node;
2371  final OverScope overScope = new OverScope(usingScope, call);
2372  scopes.put(call, overScope);
2373  operand = call.operand(0);
2374  newOperand =
2375  registerFrom(
2376  parentScope,
2377  overScope,
2378  true,
2379  operand,
2380  enclosingNode,
2381  alias,
2382  extendList,
2383  forceNullable,
2384  lateral);
2385  if (newOperand != operand) {
2386  call.setOperand(0, newOperand);
2387  }
2388 
2389  for (ScopeChild child : overScope.children) {
2390  registerNamespace(register ? usingScope : null, child.name,
2391  child.namespace, forceNullable);
2392  }
2393 
2394  return newNode;
2395 
2396  case TABLE_REF:
2397  call = (SqlCall) node;
2398  registerFrom(parentScope,
2399  usingScope,
2400  register,
2401  call.operand(0),
2402  enclosingNode,
2403  alias,
2404  extendList,
2405  forceNullable,
2406  lateral);
2407  if (extendList != null && extendList.size() != 0) {
2408  return enclosingNode;
2409  }
2410  return newNode;
2411 
2412  case EXTEND:
2413  final SqlCall extend = (SqlCall) node;
2414  return registerFrom(parentScope,
2415  usingScope,
2416  true,
2417  extend.getOperandList().get(0),
2418  extend,
2419  alias,
2420  (SqlNodeList) extend.getOperandList().get(1),
2421  forceNullable,
2422  lateral);
2423 
2424  case SNAPSHOT:
2425  call = (SqlCall) node;
2426  operand = call.operand(0);
2427  newOperand = registerFrom(
2428  parentScope,
2429  usingScope,
2430  register,
2431  operand,
2432  enclosingNode,
2433  alias,
2434  extendList,
2435  forceNullable,
2436  lateral);
2437  if (newOperand != operand) {
2438  call.setOperand(0, newOperand);
2439  }
2440  // Put the usingScope which can be a JoinScope
2441  // or a SelectScope, in order to see the left items
2442  // of the JOIN tree.
2443  scopes.put(node, usingScope);
2444  return newNode;
2445 
2446  default:
2447  throw Util.unexpected(kind);
2448  }
2449  }
void registerSubQueries(SqlValidatorScope parentScope, SqlNode node)
SqlNode registerFrom(SqlValidatorScope parentScope, SqlValidatorScope usingScope, boolean register, final SqlNode node, SqlNode enclosingNode, String alias, SqlNodeList extendList, boolean forceNullable, final boolean lateral)
std::string join(T const &container, std::string const &delim)
void registerMatchRecognize(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlMatchRecognize call, SqlNode enclosingNode, String alias, boolean forceNullable)
void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
SqlValidatorScope getSelectScope(SqlSelect select)
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
void registerNamespace(SqlValidatorScope usingScope, String alias, SqlValidatorNamespace ns, boolean forceNullable)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.registerMatchRecognize ( SqlValidatorScope  parentScope,
SqlValidatorScope  usingScope,
SqlMatchRecognize  call,
SqlNode  enclosingNode,
String  alias,
boolean  forceNullable 
)
inlineprivate

Definition at line 2012 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.createMatchRecognizeNameSpace(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerFrom(), and org.apache.calcite.sql.validate.SqlValidatorImpl.registerNamespace().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.registerFrom().

2018  {
2019 
2020  final MatchRecognizeNamespace matchRecognizeNamespace =
2021  createMatchRecognizeNameSpace(call, enclosingNode);
2022  registerNamespace(usingScope, alias, matchRecognizeNamespace, forceNullable);
2023 
2024  final MatchRecognizeScope matchRecognizeScope =
2025  new MatchRecognizeScope(parentScope, call);
2026  scopes.put(call, matchRecognizeScope);
2027 
2028  // parse input query
2029  SqlNode expr = call.getTableRef();
2030  SqlNode newExpr = registerFrom(usingScope, matchRecognizeScope, true, expr,
2031  expr, null, null, forceNullable, false);
2032  if (expr != newExpr) {
2033  call.setOperand(0, newExpr);
2034  }
2035  }
SqlNode registerFrom(SqlValidatorScope parentScope, SqlValidatorScope usingScope, boolean register, final SqlNode node, SqlNode enclosingNode, String alias, SqlNodeList extendList, boolean forceNullable, final boolean lateral)
MatchRecognizeNamespace createMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode)
void registerNamespace(SqlValidatorScope usingScope, String alias, SqlValidatorNamespace ns, boolean forceNullable)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.registerNamespace ( SqlValidatorScope  usingScope,
String  alias,
SqlValidatorNamespace  ns,
boolean  forceNullable 
)
inlineprotected

Registers a new namespace, and adds it as a child of its parent scope. Derived class can override this method to tinker with namespaces as they are created.

Parameters
usingScopeParent scope (which will want to look for things in this namespace)
aliasAlias by which parent will refer to this namespace
nsNamespace
forceNullableWhether to force the type of namespace to be nullable

Definition at line 2054 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.alias().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.declareCursor(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerFrom(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerMatchRecognize(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerSetop(), and org.apache.calcite.sql.validate.SqlValidatorImpl.registerWith().

2058  {
2059  namespaces.put(ns.getNode(), ns);
2060  if (usingScope != null) {
2061  usingScope.addChild(ns, alias, forceNullable);
2062  }
2063  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.registerOperandSubQueries ( SqlValidatorScope  parentScope,
SqlCall  call,
int  operandOrdinal 
)
inlineprivate

Registers any sub-queries inside a given call operand, and converts the operand to a scalar sub-query if the operator requires it.

Parameters
parentScopeParent scope
callCall
operandOrdinalOrdinal of operand within call
See Also
SqlOperator::argumentMustBeScalar(int)

Definition at line 3009 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.registerSubQueries().

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), and org.apache.calcite.sql.validate.SqlValidatorImpl.registerSubQueries().

3012  {
3013  SqlNode operand = call.operand(operandOrdinal);
3014  if (operand == null) {
3015  return;
3016  }
3017  if (operand.getKind().belongsTo(SqlKind.QUERY)
3018  && call.getOperator().argumentMustBeScalar(operandOrdinal)) {
3019  operand =
3020  SqlStdOperatorTable.SCALAR_QUERY.createCall(
3021  operand.getParserPosition(),
3022  operand);
3023  call.setOperand(operandOrdinal, operand);
3024  }
3025  registerSubQueries(parentScope, operand);
3026  }
void registerSubQueries(SqlValidatorScope parentScope, SqlNode node)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery ( SqlValidatorScope  parentScope,
SqlValidatorScope  usingScope,
SqlNode  node,
SqlNode  enclosingNode,
String  alias,
boolean  forceNullable 
)
inlineprivate

Registers a query in a parent scope.

Parameters
parentScopeParent scope which this scope turns to in order to resolve objects
usingScopeScope whose child list this scope should add itself to
nodeQuery node
aliasName of this query within its parent. Must be specified if usingScope != null

Definition at line 2494 of file SqlValidatorImpl.java.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.lookupHints(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerFrom(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerSetop(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerSubQueries(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerWith(), and org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression().

2500  {
2501  Preconditions.checkArgument(usingScope == null || alias != null);
2502  registerQuery(
2503  parentScope,
2504  usingScope,
2505  node,
2506  enclosingNode,
2507  alias,
2508  forceNullable,
2509  true);
2510  }
void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery ( SqlValidatorScope  parentScope,
SqlValidatorScope  usingScope,
SqlNode  node,
SqlNode  enclosingNode,
String  alias,
boolean  forceNullable,
boolean  checkUpdate 
)
inlineprivate

Registers a query in a parent scope.

Parameters
parentScopeParent scope which this scope turns to in order to resolve objects
usingScopeScope whose child list this scope should add itself to
nodeQuery node
aliasName of this query within its parent. Must be specified if usingScope != null
checkUpdateif true, validate that the update feature is supported if validating the update statement

Definition at line 2524 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.clauseScopes, org.apache.calcite.sql.validate.SqlValidatorImpl.createSelectNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.deriveAlias(), org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.GROUP_BY, org.apache.calcite.sql.validate.SqlValidatorImpl.isAggregate(), org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), org.apache.calcite.sql.validate.SqlValidatorImpl.nextGeneratedId, org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.ORDER, org.apache.calcite.sql.validate.SqlValidatorImpl.registerFrom(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerNamespace(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerOperandSubQueries(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerQuery(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerSetop(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerSubQueries(), org.apache.calcite.sql.validate.SqlValidatorImpl.registerWith(), org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.SELECT, UNION, org.apache.calcite.sql.validate.SqlValidatorImpl.validateFeature(), and org.apache.calcite.sql.validate.SqlValidatorImpl.Clause.WHERE.

2531  {
2532  Objects.requireNonNull(node);
2533  Objects.requireNonNull(enclosingNode);
2534  Preconditions.checkArgument(usingScope == null || alias != null);
2535 
2536  SqlCall call;
2537  List<SqlNode> operands;
2538  switch (node.getKind()) {
2539  case SELECT:
2540  final SqlSelect select = (SqlSelect) node;
2541  final SelectNamespace selectNs =
2542  createSelectNamespace(select, enclosingNode);
2543  registerNamespace(usingScope, alias, selectNs, forceNullable);
2544  final SqlValidatorScope windowParentScope =
2545  (usingScope != null) ? usingScope : parentScope;
2546  SelectScope selectScope =
2547  new SelectScope(parentScope, windowParentScope, select);
2548  scopes.put(select, selectScope);
2549 
2550  // Start by registering the WHERE clause
2551  clauseScopes.put(IdPair.of(select, Clause.WHERE), selectScope);
2553  selectScope,
2554  select,
2555  SqlSelect.WHERE_OPERAND);
2556 
2557  // Register FROM with the inherited scope 'parentScope', not
2558  // 'selectScope', otherwise tables in the FROM clause would be
2559  // able to see each other.
2560  final SqlNode from = select.getFrom();
2561  if (from != null) {
2562  final SqlNode newFrom =
2563  registerFrom(
2564  parentScope,
2565  selectScope,
2566  true,
2567  from,
2568  from,
2569  null,
2570  null,
2571  false,
2572  false);
2573  if (newFrom != from) {
2574  select.setFrom(newFrom);
2575  }
2576  }
2577 
2578  // If this is an aggregating query, the SELECT list and HAVING
2579  // clause use a different scope, where you can only reference
2580  // columns which are in the GROUP BY clause.
2581  SqlValidatorScope aggScope = selectScope;
2582  if (isAggregate(select)) {
2583  aggScope =
2584  new AggregatingSelectScope(selectScope, select, false);
2585  clauseScopes.put(IdPair.of(select, Clause.SELECT), aggScope);
2586  } else {
2587  clauseScopes.put(IdPair.of(select, Clause.SELECT), selectScope);
2588  }
2589  if (select.getGroup() != null) {
2590  GroupByScope groupByScope =
2591  new GroupByScope(selectScope, select.getGroup(), select);
2592  clauseScopes.put(IdPair.of(select, Clause.GROUP_BY), groupByScope);
2593  registerSubQueries(groupByScope, select.getGroup());
2594  }
2596  aggScope,
2597  select,
2598  SqlSelect.HAVING_OPERAND);
2599  registerSubQueries(aggScope, select.getSelectList());
2600  final SqlNodeList orderList = select.getOrderList();
2601  if (orderList != null) {
2602  // If the query is 'SELECT DISTINCT', restrict the columns
2603  // available to the ORDER BY clause.
2604  if (select.isDistinct()) {
2605  aggScope =
2606  new AggregatingSelectScope(selectScope, select, true);
2607  }
2608  OrderByScope orderScope =
2609  new OrderByScope(aggScope, orderList, select);
2610  clauseScopes.put(IdPair.of(select, Clause.ORDER), orderScope);
2611  registerSubQueries(orderScope, orderList);
2612 
2613  if (!isAggregate(select)) {
2614  // Since this is not an aggregating query,
2615  // there cannot be any aggregates in the ORDER BY clause.
2616  SqlNode agg = aggFinder.findAgg(orderList);
2617  if (agg != null) {
2618  throw newValidationError(agg, RESOURCE.aggregateIllegalInOrderBy());
2619  }
2620  }
2621  }
2622  break;
2623 
2624  case INTERSECT:
2625  validateFeature(RESOURCE.sQLFeature_F302(), node.getParserPosition());
2626  registerSetop(
2627  parentScope,
2628  usingScope,
2629  node,
2630  node,
2631  alias,
2632  forceNullable);
2633  break;
2634 
2635  case EXCEPT:
2636  validateFeature(RESOURCE.sQLFeature_E071_03(), node.getParserPosition());
2637  registerSetop(
2638  parentScope,
2639  usingScope,
2640  node,
2641  node,
2642  alias,
2643  forceNullable);
2644  break;
2645 
2646  case UNION:
2647  registerSetop(
2648  parentScope,
2649  usingScope,
2650  node,
2651  node,
2652  alias,
2653  forceNullable);
2654  break;
2655 
2656  case WITH:
2657  registerWith(parentScope, usingScope, (SqlWith) node, enclosingNode,
2658  alias, forceNullable, checkUpdate);
2659  break;
2660 
2661  case VALUES:
2662  call = (SqlCall) node;
2663  scopes.put(call, parentScope);
2664  final TableConstructorNamespace tableConstructorNamespace =
2665  new TableConstructorNamespace(
2666  this,
2667  call,
2668  parentScope,
2669  enclosingNode);
2671  usingScope,
2672  alias,
2673  tableConstructorNamespace,
2674  forceNullable);
2675  operands = call.getOperandList();
2676  for (int i = 0; i < operands.size(); ++i) {
2677  assert operands.get(i).getKind() == SqlKind.ROW;
2678 
2679  // FIXME jvs 9-Feb-2005: Correlation should
2680  // be illegal in these sub-queries. Same goes for
2681  // any non-lateral SELECT in the FROM list.
2682  registerOperandSubQueries(parentScope, call, i);
2683  }
2684  break;
2685 
2686  case INSERT:
2687  SqlInsert insertCall = (SqlInsert) node;
2688  InsertNamespace insertNs =
2689  new InsertNamespace(
2690  this,
2691  insertCall,
2692  enclosingNode,
2693  parentScope);
2694  registerNamespace(usingScope, null, insertNs, forceNullable);
2695  registerQuery(
2696  parentScope,
2697  usingScope,
2698  insertCall.getSource(),
2699  enclosingNode,
2700  null,
2701  false);
2702  break;
2703 
2704  case DELETE:
2705  SqlDelete deleteCall = (SqlDelete) node;
2706  DeleteNamespace deleteNs =
2707  new DeleteNamespace(
2708  this,
2709  deleteCall,
2710  enclosingNode,
2711  parentScope);
2712  registerNamespace(usingScope, null, deleteNs, forceNullable);
2713  registerQuery(
2714  parentScope,
2715  usingScope,
2716  deleteCall.getSourceSelect(),
2717  enclosingNode,
2718  null,
2719  false);
2720  break;
2721 
2722  case UPDATE:
2723  if (checkUpdate) {
2724  validateFeature(RESOURCE.sQLFeature_E101_03(),
2725  node.getParserPosition());
2726  }
2727  SqlUpdate updateCall = (SqlUpdate) node;
2728  UpdateNamespace updateNs =
2729  new UpdateNamespace(
2730  this,
2731  updateCall,
2732  enclosingNode,
2733  parentScope);
2734  registerNamespace(usingScope, null, updateNs, forceNullable);
2735  registerQuery(
2736  parentScope,
2737  usingScope,
2738  updateCall.getSourceSelect(),
2739  enclosingNode,
2740  null,
2741  false);
2742  break;
2743 
2744  case MERGE:
2745  validateFeature(RESOURCE.sQLFeature_F312(), node.getParserPosition());
2746  SqlMerge mergeCall = (SqlMerge) node;
2747  MergeNamespace mergeNs =
2748  new MergeNamespace(
2749  this,
2750  mergeCall,
2751  enclosingNode,
2752  parentScope);
2753  registerNamespace(usingScope, null, mergeNs, forceNullable);
2754  registerQuery(
2755  parentScope,
2756  usingScope,
2757  mergeCall.getSourceSelect(),
2758  enclosingNode,
2759  null,
2760  false);
2761 
2762  // update call can reference either the source table reference
2763  // or the target table, so set its parent scope to the merge's
2764  // source select; when validating the update, skip the feature
2765  // validation check
2766  if (mergeCall.getUpdateCall() != null) {
2767  registerQuery(
2768  clauseScopes.get(IdPair.of(mergeCall.getSourceSelect(), Clause.WHERE)),
2769  null,
2770  mergeCall.getUpdateCall(),
2771  enclosingNode,
2772  null,
2773  false,
2774  false);
2775  }
2776  if (mergeCall.getInsertCall() != null) {
2777  registerQuery(
2778  parentScope,
2779  null,
2780  mergeCall.getInsertCall(),
2781  enclosingNode,
2782  null,
2783  false);
2784  }
2785  break;
2786 
2787  case UNNEST:
2788  call = (SqlCall) node;
2789  final UnnestNamespace unnestNs =
2790  new UnnestNamespace(this, call, parentScope, enclosingNode);
2792  usingScope,
2793  alias,
2794  unnestNs,
2795  forceNullable);
2796  registerOperandSubQueries(parentScope, call, 0);
2797  scopes.put(node, parentScope);
2798  break;
2799  case OTHER_FUNCTION:
2800  call = (SqlCall) node;
2801  ProcedureNamespace procNs =
2802  new ProcedureNamespace(
2803  this,
2804  parentScope,
2805  call,
2806  enclosingNode);
2808  usingScope,
2809  alias,
2810  procNs,
2811  forceNullable);
2812  registerSubQueries(parentScope, call);
2813  break;
2814 
2815  case MULTISET_QUERY_CONSTRUCTOR:
2816  case MULTISET_VALUE_CONSTRUCTOR:
2817  validateFeature(RESOURCE.sQLFeature_S271(), node.getParserPosition());
2818  call = (SqlCall) node;
2819  CollectScope cs = new CollectScope(parentScope, usingScope, call);
2820  final CollectNamespace tableConstructorNs =
2821  new CollectNamespace(call, cs, enclosingNode);
2822  final String alias2 = deriveAlias(node, nextGeneratedId++);
2824  usingScope,
2825  alias2,
2826  tableConstructorNs,
2827  forceNullable);
2828  operands = call.getOperandList();
2829  for (int i = 0; i < operands.size(); i++) {
2830  registerOperandSubQueries(parentScope, call, i);
2831  }
2832  break;
2833 
2834  default:
2835  throw Util.unexpected(node.getKind());
2836  }
2837  }
void registerSubQueries(SqlValidatorScope parentScope, SqlNode node)
SqlNode registerFrom(SqlValidatorScope parentScope, SqlValidatorScope usingScope, boolean register, final SqlNode node, SqlNode enclosingNode, String alias, SqlNodeList extendList, boolean forceNullable, final boolean lateral)
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
void registerQuery(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
SelectNamespace createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
void registerSetop(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, String alias, boolean forceNullable)
final Map< IdPair< SqlSelect, Clause >, SqlValidatorScope > clauseScopes
void registerWith(SqlValidatorScope parentScope, SqlValidatorScope usingScope, SqlWith with, SqlNode enclosingNode, String alias, boolean forceNullable, boolean checkUpdate)
void registerOperandSubQueries(SqlValidatorScope parentScope, SqlCall call, int operandOrdinal)