OmniSciDB  c1a53651b2
 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 176 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 297 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(), File_Namespace.create(), 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.

301  {
302  this.opTab = Objects.requireNonNull(opTab);
303  this.catalogReader = Objects.requireNonNull(catalogReader);
304  this.typeFactory = Objects.requireNonNull(typeFactory);
305  this.config = Objects.requireNonNull(config);
306 
307  unknownType = typeFactory.createUnknownType();
308  booleanType = typeFactory.createSqlType(SqlTypeName.BOOLEAN);
309 
310  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
311  aggFinder = new AggFinder(opTab, false, true, false, null, nameMatcher);
313  new AggFinder(opTab, true, true, false, null, nameMatcher);
314  overFinder = new AggFinder(opTab, true, false, false, aggOrOverFinder,
315  nameMatcher);
316  groupFinder = new AggFinder(opTab, false, false, true, null, nameMatcher);
317  aggOrOverOrGroupFinder = new AggFinder(opTab, true, true, true, null,
318  nameMatcher);
319  this.typeCoercion = config.typeCoercionFactory().create(typeFactory, this);
320  if (config.typeCoercionRules() != null) {
321  SqlTypeCoercionRule.THREAD_PROVIDERS.set(config.typeCoercionRules());
322  }
323  }
std::pair< FILE *, std::string > create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:57

+ 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 719 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().

721  {
722  switch (field.getType().getStructKind()) {
723  case PEEK_FIELDS:
724  case PEEK_FIELDS_DEFAULT:
725  final SqlNode starExp = id.plusStar();
726  expandStar(
727  selectItems,
728  aliases,
729  fields,
730  includeSystemVars,
731  scope,
732  starExp);
733  return true;
734 
735  default:
737  selectItems,
738  aliases,
739  fields,
740  id,
741  scope,
742  includeSystemVars);
743  }
744 
745  return false;
746  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
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 1981 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().

1987  {
1988  String alias = SqlValidatorUtil.getAlias(exp, -1);
1989  String uniqueAlias =
1990  SqlValidatorUtil.uniquify(
1991  alias, aliases, SqlValidatorUtil.EXPR_SUGGESTER);
1992  if (!Objects.equals(alias, uniqueAlias)) {
1993  exp = SqlValidatorUtil.addAlias(exp, uniqueAlias);
1994  }
1995  fieldList.add(Pair.of(uniqueAlias, deriveType(scope, exp)));
1996  list.add(exp);
1997  }
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 4428 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().

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

+ 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 4482 of file SqlValidatorImpl.java.

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

4485  {
4486  final ModifiableViewTable modifiableViewTable =
4487  validatorTable.unwrap(ModifiableViewTable.class);
4488  if (modifiableViewTable != null) {
4489  final Table table = modifiableViewTable.unwrap(Table.class);
4490  final RelDataType tableRowType = table.getRowType(typeFactory);
4491 
4492  final Map<Integer, RexNode> projectMap =
4493  RelOptUtil.getColumnConstraints(modifiableViewTable, targetRowType,
4494  typeFactory);
4495  final Map<String, Integer> nameToIndex =
4496  SqlValidatorUtil.mapNameToIndex(tableRowType.getFieldList());
4497 
4498  // Validate update values against the view constraint.
4499  final List<SqlNode> targets = update.getTargetColumnList().getList();
4500  final List<SqlNode> sources = update.getSourceExpressionList().getList();
4501  for (final Pair<SqlNode, SqlNode> column : Pair.zip(targets, sources)) {
4502  final String columnName = ((SqlIdentifier) column.left).getSimple();
4503  final Integer columnIndex = nameToIndex.get(columnName);
4504  if (projectMap.containsKey(columnIndex)) {
4505  final RexNode columnConstraint = projectMap.get(columnIndex);
4506  final ValidationError validationError =
4507  new ValidationError(column.right,
4508  RESOURCE.viewConstraintNotSatisfied(columnName,
4509  Util.last(validatorTable.getQualifiedName())));
4510  RelOptUtil.validateValueAgainstConstraint(column.right,
4511  columnConstraint, validationError);
4512  }
4513  }
4514  }
4515  }
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 4532 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().

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

3533  {
3534  current = stripAs(current);
3535  if (current instanceof SqlCall && !(current instanceof SqlSelect)) {
3536  // Validate OVER separately
3537  checkRollUpInWindow(getWindowInOver(current), scope);
3538  current = stripOver(current);
3539 
3540  List<SqlNode> children = ((SqlCall) stripAs(stripDot(current))).getOperandList();
3541  for (SqlNode child : children) {
3542  checkRollUp(parent, current, child, scope, optionalClause);
3543  }
3544  } else if (current instanceof SqlIdentifier) {
3545  SqlIdentifier id = (SqlIdentifier) current;
3546  if (!id.isStar() && isRolledUpColumn(id, scope)) {
3547  if (!isAggregation(parent.getKind())
3548  || !isRolledUpColumnAllowedInAgg(id, scope, (SqlCall) parent, grandParent)) {
3549  String context = optionalClause != null ? optionalClause : parent.getKind().toString();
3550  throw newValidationError(id,
3551  RESOURCE.rolledUpNotAllowed(deriveAlias(id, 0), context));
3552  }
3553  }
3554  }
3555  }
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
void checkRollUpInWindow(SqlWindow window, SqlValidatorScope scope)
std::string toString(const ExecutorDeviceType &device_type)
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 3557 of file SqlValidatorImpl.java.

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

3558  {
3559  checkRollUp(grandParent, parent, current, scope, null);
3560  }
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 3489 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().

3489  {
3490  SqlNodeList group = select.getGroup();
3491  if (group != null) {
3492  for (SqlNode node : group) {
3493  checkRollUp(null, select, node, getGroupScope(select), "GROUP BY");
3494  }
3495  }
3496  }
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 3498 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().

3498  {
3499  SqlNodeList orderList = select.getOrderList();
3500  if (orderList != null) {
3501  for (SqlNode node : orderList) {
3502  checkRollUp(null, select, node, getOrderScope(select), "ORDER BY");
3503  }
3504  }
3505  }
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 3482 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().

3482  {
3483  SqlValidatorScope scope = getSelectScope(select);
3484  for (SqlNode item : select.getSelectList()) {
3485  checkRollUp(null, select, item, scope);
3486  }
3487  }
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 3216 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().

3217  {
3218  SqlValidatorNamespace namespace = getNamespace(leftOrRight, scope);
3219  if (namespace != null) {
3220  SqlValidatorTable sqlValidatorTable = namespace.getTable();
3221  if (sqlValidatorTable != null) {
3222  Table table = sqlValidatorTable.unwrap(Table.class);
3223  String column = Util.last(identifier.names);
3224 
3225  if (table.isRolledUp(column)) {
3226  throw newValidationError(identifier,
3227  RESOURCE.rolledUpNotAllowed(column, "USING"));
3228  }
3229  }
3230  }
3231  }
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 3507 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().

3507  {
3508  if (window != null) {
3509  for (SqlNode node : window.getPartitionList()) {
3510  checkRollUp(null, window, node, scope, "PARTITION BY");
3511  }
3512 
3513  for (SqlNode node : window.getOrderList()) {
3514  checkRollUp(null, window, node, scope, "ORDER BY");
3515  }
3516  }
3517  }
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 3519 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().

3519  {
3520  for (SqlNode decl : select.getWindowList()) {
3521  checkRollUpInWindow((SqlWindow) decl, getSelectScope(select));
3522  }
3523  }
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 4642 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().

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

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

2036  {
2037  return new MatchRecognizeNamespace(this, call, enclosingNode);
2038  }

+ 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 2460 of file SqlValidatorImpl.java.

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

2462  {
2463  return new SelectNamespace(this, select, enclosingNode);
2464  }

+ 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 2475 of file SqlValidatorImpl.java.

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

2477  {
2478  return new SetopNamespace(this, call, enclosingNode);
2479  }

+ 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 1634 of file SqlValidatorImpl.java.

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

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

+ 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 1605 of file SqlValidatorImpl.java.

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

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

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

+ 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 4313 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().

4316  {
4317  RelDataType baseRowType = table.getRowType();
4318  if (targetColumnList == null) {
4319  return baseRowType;
4320  }
4321  List<RelDataTypeField> targetFields = baseRowType.getFieldList();
4322  final List<Map.Entry<String, RelDataType>> fields = new ArrayList<>();
4323  if (append) {
4324  for (RelDataTypeField targetField : targetFields) {
4325  fields.add(
4326  Pair.of(SqlUtil.deriveAliasFromOrdinal(fields.size()),
4327  targetField.getType()));
4328  }
4329  }
4330  final Set<Integer> assignedFields = new HashSet<>();
4331  final RelOptTable relOptTable = table instanceof RelOptTable
4332  ? ((RelOptTable) table) : null;
4333  for (SqlNode node : targetColumnList) {
4334  SqlIdentifier id = (SqlIdentifier) node;
4335  RelDataTypeField targetField =
4336  SqlValidatorUtil.getTargetField(
4337  baseRowType, typeFactory, id, catalogReader, relOptTable);
4338  if (targetField == null) {
4339  throw newValidationError(id,
4340  RESOURCE.unknownTargetColumn(id.toString()));
4341  }
4342  if (!assignedFields.add(targetField.getIndex())) {
4343  throw newValidationError(id,
4344  RESOURCE.duplicateTargetColumn(targetField.getName()));
4345  }
4346  fields.add(targetField);
4347  }
4348  return typeFactory.createStructType(fields);
4349  }
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:178
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 370 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().

370  {
371  cursorSet.add(select);
372 
373  // add the cursor to a map that maps the cursor to its select based on
374  // the position of the cursor relative to other cursors in that call
375  FunctionParamInfo funcParamInfo = functionCallStack.peek();
376  Map<Integer, SqlSelect> cursorMap = funcParamInfo.cursorPosToSelectMap;
377  int numCursors = cursorMap.size();
378  cursorMap.put(numCursors, select);
379 
380  // create a namespace associated with the result of the select
381  // that is the argument to the cursor constructor; register it
382  // with a scope corresponding to the cursor
383  SelectScope cursorScope = new SelectScope(parentScope, null, select);
384  clauseScopes.put(IdPair.of(select, Clause.CURSOR), cursorScope);
385  final SelectNamespace selectNs = createSelectNamespace(select, select);
386  String alias = deriveAlias(select, nextGeneratedId++);
387  registerNamespace(cursorScope, alias, selectNs, false);
388  }
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 3674 of file SqlValidatorImpl.java.

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

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

+ 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 1787 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.

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

1755  {
1756  Objects.requireNonNull(scope);
1757  Objects.requireNonNull(expr);
1758 
1759  // if we already know the type, no need to re-derive
1760  RelDataType type = nodeToTypeMap.get(expr);
1761  if (type != null) {
1762  return type;
1763  }
1764  final SqlValidatorNamespace ns = getNamespace(expr);
1765  if (ns != null) {
1766  return ns.getType();
1767  }
1768  type = deriveTypeImpl(scope, expr);
1769  Preconditions.checkArgument(
1770  type != null,
1771  "SqlValidator.deriveTypeInternal returned null");
1772  setValidatedNodeType(expr, type);
1773  return type;
1774  }
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 1779 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().

1781  {
1782  DeriveTypeVisitor v = new DeriveTypeVisitor(scope);
1783  final RelDataType type = operand.accept(v);
1784  return Objects.requireNonNull(scope.nullifyType(operand, type));
1785  }

+ Here is the caller graph for this function:

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

Definition at line 5521 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().

5521  {
5522  final Expander expander = new Expander(this, scope);
5523  SqlNode newExpr = expr.accept(expander);
5524  if (expr != newExpr) {
5525  setOriginal(newExpr, expr);
5526  }
5527  return newExpr;
5528  }
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 540 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().

541  {
542  if (!(selectItem instanceof SqlIdentifier)) {
543  return selectItem;
544  }
545 
546  final SqlNode from = sqlSelect.getFrom();
547  if (!(from instanceof SqlJoin)) {
548  return selectItem;
549  }
550 
551  final SqlIdentifier identifier = (SqlIdentifier) selectItem;
552  if (!identifier.isSimple()) {
553  if (!validator.config().sqlConformance().allowQualifyingCommonColumn()) {
554  validateQualifiedCommonColumn((SqlJoin) from, identifier, scope, validator);
555  }
556  return selectItem;
557  }
558 
559  return expandExprFromJoin((SqlJoin) from, identifier, scope);
560  }
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 473 of file SqlValidatorImpl.java.

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

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

474  {
475  if (join.getConditionType() != JoinConditionType.USING) {
476  return identifier;
477  }
478 
479  for (SqlNode node : (SqlNodeList) join.getCondition()) {
480  final String name = ((SqlIdentifier) node).getSimple();
481  if (identifier.getSimple().equals(name)) {
482  final List<SqlNode> qualifiedNode = new ArrayList<>();
483  for (ScopeChild child : scope.children) {
484  if (child.namespace.getRowType()
485  .getFieldNames().indexOf(name) >= 0) {
486  final SqlIdentifier exp =
487  new SqlIdentifier(
488  ImmutableList.of(child.name, name),
489  identifier.getParserPosition());
490  qualifiedNode.add(exp);
491  }
492  }
493 
494  assert qualifiedNode.size() == 2;
495  final SqlNode finalNode =
496  SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO,
497  SqlStdOperatorTable.COALESCE.createCall(SqlParserPos.ZERO,
498  qualifiedNode.get(0),
499  qualifiedNode.get(1)),
500  new SqlIdentifier(name, SqlParserPos.ZERO));
501  return finalNode;
502  }
503  }
504 
505  // Only need to try to expand the expr from the left input of join
506  // since it is always left-deep join.
507  final SqlNode node = join.getLeft();
508  if (node instanceof SqlJoin) {
509  return expandExprFromJoin((SqlJoin) node, identifier, scope);
510  } else {
511  return identifier;
512  }
513  }
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 5530 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().

5531  {
5532  final Expander expander = new ExtendedExpander(this, scope, select, expr,
5533  havingExpression);
5534  SqlNode newExpr = expr.accept(expander);
5535  if (expr != newExpr) {
5536  setOriginal(newExpr, expr);
5537  }
5538  return newExpr;
5539  }
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 4006 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.

4006  {
4007  final SqlNode newSqlNode =
4008  new OrderExpressionExpander(select, orderExpr).go();
4009  if (newSqlNode != orderExpr) {
4010  final SqlValidatorScope scope = getOrderScope(select);
4011  inferUnknownTypes(unknownType, scope, newSqlNode);
4012  final RelDataType type = deriveType(scope, newSqlNode);
4013  setValidatedNodeType(newSqlNode, type);
4014  }
4015  return newSqlNode;
4016  }
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 5511 of file SqlValidatorImpl.java.

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

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

5512  {
5513  final Expander expander = new SelectExpander(this, scope, select);
5514  final SqlNode newExpr = expr.accept(expander);
5515  if (expr != newExpr) {
5516  setOriginal(newExpr, expr);
5517  }
5518  return newExpr;
5519  }
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 421 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().

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

350  {
351  final List<SqlNode> list = new ArrayList<>();
352  final List<Map.Entry<String, RelDataType>> types = new ArrayList<>();
353  for (int i = 0; i < selectList.size(); i++) {
354  final SqlNode selectItem = selectList.get(i);
355  final RelDataType originalType = getValidatedNodeTypeIfKnown(selectItem);
357  selectItem,
358  select,
359  Util.first(originalType, unknownType),
360  list,
361  catalogReader.nameMatcher().createSet(),
362  types,
363  includeSystemVars);
364  }
365  getRawSelectScope(select).setExpandedSelectList(list);
366  return new SqlNodeList(list, SqlParserPos.ZERO);
367  }
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 589 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.

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

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

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

+ 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 968 of file SqlValidatorImpl.java.

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

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

+ 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 3583 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().

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

+ 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 2939 of file SqlValidatorImpl.java.

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

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

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

+ 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 2925 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().

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

+ 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 331 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().

331  {
332  return catalogReader;
333  }

+ Here is the caller graph for this function:

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

Definition at line 327 of file SqlValidatorImpl.java.

327  {
328  return config.sqlConformance();
329  }
SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.getCursorScope ( SqlSelect  select)
inline

Definition at line 1105 of file SqlValidatorImpl.java.

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

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

Definition at line 1101 of file SqlValidatorImpl.java.

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

Definition at line 5561 of file SqlValidatorImpl.java.

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

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

5561  {
5562  if (sqlQuery instanceof SqlSelect) {
5563  SqlSelect sqlSelect = (SqlSelect) sqlQuery;
5564  final SelectScope scope = getRawSelectScope(sqlSelect);
5565  final List<SqlNode> selectList = scope.getExpandedSelectList();
5566  final SqlNode selectItem = stripAs(selectList.get(i));
5567  if (selectItem instanceof SqlIdentifier) {
5568  final SqlQualified qualified =
5569  scope.fullyQualify((SqlIdentifier) selectItem);
5570  SqlValidatorNamespace namespace = qualified.namespace;
5571  final SqlValidatorTable table = namespace.getTable();
5572  if (table == null) {
5573  return null;
5574  }
5575  final List<String> origin =
5576  new ArrayList<>(table.getQualifiedName());
5577  for (String name : qualified.suffix()) {
5578  namespace = namespace.lookupChild(name);
5579  if (namespace == null) {
5580  return null;
5581  }
5582  origin.add(name);
5583  }
5584  return origin;
5585  }
5586  return null;
5587  } else if (sqlQuery instanceof SqlOrderBy) {
5588  return getFieldOrigin(((SqlOrderBy) sqlQuery).query, i);
5589  } else {
5590  return null;
5591  }
5592  }
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 5545 of file SqlValidatorImpl.java.

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

5545  {
5546  if (sqlQuery instanceof SqlExplain) {
5547  return Collections.emptyList();
5548  }
5549  final RelDataType rowType = getValidatedNodeType(sqlQuery);
5550  final int fieldCount = rowType.getFieldCount();
5551  if (!sqlQuery.isA(SqlKind.QUERY)) {
5552  return Collections.nCopies(fieldCount, null);
5553  }
5554  final List<List<String>> list = new ArrayList<>();
5555  for (int i = 0; i < fieldCount; i++) {
5556  list.add(getFieldOrigin(sqlQuery, i));
5557  }
5558  return ImmutableNullableList.copyOf(list);
5559  }
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 1135 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().

1135  {
1136  return scopes.get(select);
1137  }

+ Here is the caller graph for this function:

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

Definition at line 1130 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().

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

+ Here is the caller graph for this function:

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

Definition at line 1125 of file SqlValidatorImpl.java.

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 1431 of file SqlValidatorImpl.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 1147 of file SqlValidatorImpl.java.

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

Definition at line 4622 of file SqlValidatorImpl.java.

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

4624  {
4625  return sourceRowType;
4626  }

+ Here is the caller graph for this function:

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

Definition at line 4598 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().

4600  {
4601  if (insert.getTargetColumnList() == null
4602  && this.config.sqlConformance().isInsertSubsetColumnsAllowed()) {
4603  // Target an implicit subset of columns.
4604  final SqlNode source = insert.getSource();
4605  final RelDataType sourceRowType = getNamespace(source).getRowType();
4606  final RelDataType logicalSourceRowType =
4607  getLogicalSourceRowType(sourceRowType, insert);
4608  final RelDataType implicitTargetRowType =
4609  typeFactory.createStructType(
4610  targetRowType.getFieldList()
4611  .subList(0, logicalSourceRowType.getFieldCount()));
4612  final SqlValidatorNamespace targetNamespace = getNamespace(insert);
4613  validateNamespace(targetNamespace, implicitTargetRowType);
4614  return implicitTargetRowType;
4615  } else {
4616  // Either the set of columns are explicitly targeted, or target the full
4617  // set of columns.
4618  return targetRowType;
4619  }
4620  }
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 1143 of file SqlValidatorImpl.java.

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

1143  {
1144  return scopes.get(node);
1145  }

+ Here is the caller graph for this function:

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

Definition at line 1155 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().

1156  {
1157  if (node instanceof SqlIdentifier && scope instanceof DelegatingScope) {
1158  final SqlIdentifier id = (SqlIdentifier) node;
1159  final DelegatingScope idScope = (DelegatingScope) ((DelegatingScope) scope).getParent();
1160  return getNamespace(id, idScope);
1161  } else if (node instanceof SqlCall) {
1162  // Handle extended identifiers.
1163  final SqlCall call = (SqlCall) node;
1164  switch (call.getOperator().getKind()) {
1165  case TABLE_REF:
1166  return getNamespace(call.operand(0), scope);
1167  case EXTEND:
1168  final SqlNode operand0 = call.getOperandList().get(0);
1169  final SqlIdentifier identifier = operand0.getKind() == SqlKind.TABLE_REF
1170  ? ((SqlCall) operand0).operand(0)
1171  : (SqlIdentifier) operand0;
1172  final DelegatingScope idScope = (DelegatingScope) scope;
1173  return getNamespace(identifier, idScope);
1174  case AS:
1175  final SqlNode nested = call.getOperandList().get(0);
1176  switch (nested.getKind()) {
1177  case TABLE_REF:
1178  case EXTEND:
1179  return getNamespace(nested, scope);
1180  }
1181  break;
1182  }
1183  }
1184  return getNamespace(node);
1185  }
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 1187 of file SqlValidatorImpl.java.

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

1187  {
1188  if (id.isSimple()) {
1189  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
1190  final SqlValidatorScope.ResolvedImpl resolved =
1191  new SqlValidatorScope.ResolvedImpl();
1192  scope.resolve(id.names, nameMatcher, false, resolved);
1193  if (resolved.count() == 1) {
1194  return resolved.only().namespace;
1195  }
1196  }
1197  return getNamespace(id);
1198  }
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 1200 of file SqlValidatorImpl.java.

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

1200  {
1201  switch (node.getKind()) {
1202  case AS:
1203 
1204  // AS has a namespace if it has a column list 'AS t (c1, c2, ...)'
1205  final SqlValidatorNamespace ns = namespaces.get(node);
1206  if (ns != null) {
1207  return ns;
1208  }
1209  // fall through
1210  case TABLE_REF:
1211  case SNAPSHOT:
1212  case OVER:
1213  case COLLECTION_TABLE:
1214  case ORDER_BY:
1215  case TABLESAMPLE:
1216  return getNamespace(((SqlCall) node).operand(0));
1217  default:
1218  return namespaces.get(node);
1219  }
1220  }
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 4720 of file SqlValidatorImpl.java.

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

4720  {
4721  if (query instanceof SqlInsert) {
4722  SqlInsert insert = (SqlInsert) query;
4723  if (insert.getTargetColumnList() != null) {
4724  return insert.getTargetColumnList().get(ordinal);
4725  } else {
4726  return getNthExpr(
4727  insert.getSource(),
4728  ordinal,
4729  sourceCount);
4730  }
4731  } else if (query instanceof SqlUpdate) {
4732  SqlUpdate update = (SqlUpdate) query;
4733  if (update.getSourceExpressionList() != null) {
4734  return update.getSourceExpressionList().get(ordinal);
4735  } else {
4736  return getNthExpr(
4737  update.getSourceSelect(),
4738  ordinal,
4739  sourceCount);
4740  }
4741  } else if (query instanceof SqlSelect) {
4742  SqlSelect select = (SqlSelect) query;
4743  if (select.getSelectList().size() == sourceCount) {
4744  return select.getSelectList().get(ordinal);
4745  } else {
4746  return query; // give up
4747  }
4748  } else {
4749  return query; // give up
4750  }
4751  }
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 335 of file SqlValidatorImpl.java.

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

335  {
336  return opTab;
337  }
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 5075 of file SqlValidatorImpl.java.

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

Definition at line 1151 of file SqlValidatorImpl.java.

1151  {
1152  return scopes.get(node);
1153  }
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.getParameterRowType ( SqlNode  sqlQuery)
inline

Definition at line 5594 of file SqlValidatorImpl.java.

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

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

+ Here is the call graph for this function:

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

Definition at line 402 of file SqlValidatorImpl.java.

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

Definition at line 1117 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().

1117  {
1118  SqlValidatorScope scope = getSelectScope(select);
1119  if (scope instanceof AggregatingSelectScope) {
1120  scope = ((AggregatingSelectScope) scope).getParent();
1121  }
1122  return (SelectScope) scope;
1123  }
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 1592 of file SqlValidatorImpl.java.

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

1594  {
1595  return null;
1596  }

+ 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 1652 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(), and run_benchmark_import.type.

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

3907  {
3908  assert config.typeCoercionEnabled();
3909  return this.typeCoercion;
3910  }
RelDataTypeFactory org.apache.calcite.sql.validate.SqlValidatorImpl.getTypeFactory ( )
inline

Definition at line 339 of file SqlValidatorImpl.java.

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

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

339  {
340  return typeFactory;
341  }

+ 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 1682 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().

1682  {
1683  RelDataType type = getValidatedNodeTypeIfKnown(node);
1684  if (type == null) {
1685  throw Util.needToImplement(node);
1686  } else {
1687  return type;
1688  }
1689  }

+ 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 1691 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().

1691  {
1692  final RelDataType type = nodeToTypeMap.get(node);
1693  if (type != null) {
1694  return type;
1695  }
1696  final SqlValidatorNamespace ns = getNamespace(node);
1697  if (ns != null) {
1698  return ns.getType();
1699  }
1700  final SqlNode original = originalExprs.get(node);
1701  if (original != null && original != node) {
1702  return getValidatedNodeType(original);
1703  }
1704  if (node instanceof SqlIdentifier) {
1705  return getCatalogReader().getNamedType((SqlIdentifier) node);
1706  }
1707  return null;
1708  }
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 5025 of file SqlValidatorImpl.java.

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

5025  {
5026  return validationErrorFunction;
5027  }
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 5036 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().

5038  {
5039  SqlWindow window = null;
5040  if (id.isSimple()) {
5041  final String name = id.getSimple();
5042  window = scope.lookupWindow(name);
5043  }
5044  if (window == null) {
5045  throw newValidationError(id, RESOURCE.windowNotFound(id.toString()));
5046  }
5047  return window;
5048  }
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 3562 of file SqlValidatorImpl.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 3902 of file SqlValidatorImpl.java.

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

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

Definition at line 1222 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().

1222  {
1223  if (offset instanceof SqlDynamicParam) {
1224  setValidatedNodeType(offset,
1225  typeFactory.createSqlType(SqlTypeName.INTEGER));
1226  }
1227  if (fetch instanceof SqlDynamicParam) {
1228  setValidatedNodeType(fetch,
1229  typeFactory.createSqlType(SqlTypeName.INTEGER));
1230  }
1231  }
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 4267 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().

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

1842  {
1843  // For builtins, we can give a better error message
1844  final List<SqlOperator> overloads = new ArrayList<>();
1845  opTab.lookupOperatorOverloads(unresolvedFunction.getNameAsId(), null,
1846  SqlSyntax.FUNCTION, overloads, catalogReader.nameMatcher());
1847  if (overloads.size() == 1) {
1848  SqlFunction fun = (SqlFunction) overloads.get(0);
1849  if ((fun.getSqlIdentifier() == null)
1850  && (fun.getSyntax() != SqlSyntax.FUNCTION_ID)) {
1851  final int expectedArgCount =
1852  fun.getOperandCountRange().getMin();
1853  throw newValidationError(call,
1854  RESOURCE.invalidArgCount(call.getOperator().getName(),
1855  expectedArgCount));
1856  }
1857  }
1858 
1859  AssignableOperandTypeChecker typeChecking =
1860  new AssignableOperandTypeChecker(argTypes, argNames);
1861  String signature =
1862  typeChecking.getAllowedSignatures(
1863  unresolvedFunction,
1864  unresolvedFunction.getName());
1865  throw newValidationError(call,
1866  RESOURCE.validatorUnknownFunction(signature));
1867  }
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 3775 of file SqlValidatorImpl.java.

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

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

3775  {
3776  return isSortCompatible(scope, orderList.get(0), false);
3777  }
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 1869 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().

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

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

+ 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 2951 of file SqlValidatorImpl.java.

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

Definition at line 5640 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().

5640  {
5641  return kind == SqlKind.SUM || kind == SqlKind.SUM0
5642  || kind == SqlKind.AVG || kind == SqlKind.COUNT
5643  || kind == SqlKind.MAX || kind == SqlKind.MIN;
5644  }

+ Here is the caller graph for this function:

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

Definition at line 5636 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().

5636  {
5637  return kind == SqlKind.FIRST || kind == SqlKind.LAST;
5638  }

+ Here is the caller graph for this function:

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

Definition at line 2908 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().

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

+ Here is the caller graph for this function:

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

Definition at line 2915 of file SqlValidatorImpl.java.

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

2915  {
2916  return aggFinder.findAgg(node) != null;
2917  }

+ Here is the caller graph for this function:

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

Definition at line 5632 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().

5632  {
5633  return kind == SqlKind.PREV || kind == SqlKind.NEXT;
5634  }

+ Here is the caller graph for this function:

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

Definition at line 3622 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().

3622  {
3623  Pair<String, String> pair = findTableColumnPair(identifier, scope);
3624 
3625  if (pair == null) {
3626  return false;
3627  }
3628 
3629  String columnName = pair.right;
3630 
3631  SqlValidatorTable sqlValidatorTable =
3632  scope.fullyQualify(identifier).namespace.getTable();
3633  if (sqlValidatorTable != null) {
3634  Table table = sqlValidatorTable.unwrap(Table.class);
3635  return table.isRolledUp(columnName);
3636  }
3637  return false;
3638  }
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 3600 of file SqlValidatorImpl.java.

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

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

3601  {
3602  Pair<String, String> pair = findTableColumnPair(identifier, scope);
3603 
3604  if (pair == null) {
3605  return true;
3606  }
3607 
3608  String columnName = pair.right;
3609 
3610  SqlValidatorTable sqlValidatorTable =
3611  scope.fullyQualify(identifier).namespace.getTable();
3612  if (sqlValidatorTable != null) {
3613  Table table = sqlValidatorTable.unwrap(Table.class);
3614  return table.rolledUpColumnValidInsideAgg(columnName, aggCall, parent,
3615  catalogReader.getConfig());
3616  }
3617  return true;
3618  }
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 4588 of file SqlValidatorImpl.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 5646 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().

5646  {
5647  return kind == SqlKind.RUNNING || kind == SqlKind.FINAL;
5648  }

+ Here is the caller graph for this function:

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

Definition at line 5650 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().

5650  {
5651  return isPhysicalNavigation(kind)
5652  || isLogicalNavigation(kind)
5653  || isAggregation(kind);
5654  }

+ 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 3779 of file SqlValidatorImpl.java.

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

3780  {
3781  switch (node.getKind()) {
3782  case DESCENDING:
3783  return isSortCompatible(scope, ((SqlCall) node).getOperandList().get(0),
3784  true);
3785  }
3786  final SqlMonotonicity monotonicity = scope.getMonotonicity(node);
3787  switch (monotonicity) {
3788  case INCREASING:
3789  case STRICTLY_INCREASING:
3790  return !descending;
3791  case DECREASING:
3792  case STRICTLY_DECREASING:
3793  return descending;
3794  default:
3795  return false;
3796  }
3797  }
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 5541 of file SqlValidatorImpl.java.

5541  {
5542  return false;
5543  }
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 4575 of file SqlValidatorImpl.java.

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

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

4575  {
4576  switch (source.getKind()) {
4577  case VALUES:
4578  for (SqlNode operand : ((SqlCall) source).getOperandList()) {
4579  if (!isRowWithDefault(operand, column)) {
4580  return false;
4581  }
4582  }
4583  return true;
4584  }
4585  return false;
4586  }
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 5088 of file SqlValidatorImpl.java.

References field(), and setup.name.

5088  {
5089  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
5090  final RelDataTypeField field = nameMatcher.field(rowType, name);
5091  if (field == null) {
5092  return null;
5093  }
5094  return new FieldNamespace(this, field.getType());
5095  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
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 825 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().

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

757  {
758  SqlValidatorScope scope = new EmptyScope(this);
759  SqlNode outermostNode = performUnconditionalRewrites(topNode, false);
760  cursorSet.add(outermostNode);
761  if (outermostNode.isA(SqlKind.TOP_LEVEL)) {
763  scope,
764  null,
765  outermostNode,
766  outermostNode,
767  null,
768  false);
769  }
770  final SqlValidatorNamespace ns = getNamespace(outermostNode);
771  if (ns == null) {
772  throw new AssertionError("Not a query: " + outermostNode);
773  }
774  Collection<SqlMoniker> hintList = Sets.newTreeSet(SqlMoniker.COMPARATOR);
775  lookupSelectHints(ns, pos, hintList);
776  return ImmutableList.copyOf(hintList);
777  }
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 865 of file SqlValidatorImpl.java.

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

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

869  {
870  SqlNode left = join.getLeft();
871  SqlNode right = join.getRight();
872  SqlNode condition = join.getCondition();
873  lookupFromHints(left, scope, pos, hintList);
874  if (hintList.size() > 0) {
875  return;
876  }
877  lookupFromHints(right, scope, pos, hintList);
878  if (hintList.size() > 0) {
879  return;
880  }
881  final JoinConditionType conditionType = join.getConditionType();
882  final SqlValidatorScope joinScope = scopes.get(join);
883  switch (conditionType) {
884  case ON:
885  condition.findValidOptions(this, joinScope, pos, hintList);
886  return;
887  default:
888 
889  // No suggestions.
890  // Not supporting hints for other types such as 'Using' yet.
891  }
892  }
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 902 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().

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

779  {
780  final String posString = pos.toString();
781  IdInfo info = idPositions.get(posString);
782  if (info != null) {
783  final SqlQualified qualified = info.scope.fullyQualify(info.id);
784  return new SqlIdentifierMoniker(qualified.identifier);
785  } else {
786  return null;
787  }
788  }
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 800 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().

803  {
804  IdInfo info = idPositions.get(pos.toString());
805  if ((info == null) || (info.scope == null)) {
806  SqlNode fromNode = select.getFrom();
807  final SqlValidatorScope fromScope = getFromScope(select);
808  lookupFromHints(fromNode, fromScope, pos, hintList);
809  } else {
810  lookupNameCompletionHints(info.scope, info.id.names,
811  info.id.getParserPosition(), hintList);
812  }
813  }
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 815 of file SqlValidatorImpl.java.

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

818  {
819  final SqlNode node = ns.getNode();
820  if (node instanceof SqlSelect) {
821  lookupSelectHints((SqlSelect) node, pos, hintList);
822  }
823  }
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 1734 of file SqlValidatorImpl.java.

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

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

+ 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 711 of file SqlValidatorImpl.java.

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

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

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

+ 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 5388 of file SqlValidatorImpl.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 5315 of file SqlValidatorImpl.java.

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

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

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

+ 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 5029 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().

5030  {
5031  assert node != null;
5032  final SqlParserPos pos = node.getParserPosition();
5033  return SqlUtil.newContextException(pos, e);
5034  }

+ 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 1242 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().

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

397  {
398  functionCallStack.pop();
399  }
void org.apache.calcite.sql.validate.SqlValidatorImpl.pushFunctionCall ( )
inline

Definition at line 391 of file SqlValidatorImpl.java.

391  {
392  FunctionParamInfo funcInfo = new FunctionParamInfo();
393  functionCallStack.push(funcInfo);
394  }
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 2093 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().

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

2015  {
2016 
2017  final MatchRecognizeNamespace matchRecognizeNamespace =
2018  createMatchRecognizeNameSpace(call, enclosingNode);
2019  registerNamespace(usingScope, alias, matchRecognizeNamespace, forceNullable);
2020 
2021  final MatchRecognizeScope matchRecognizeScope =
2022  new MatchRecognizeScope(parentScope, call);
2023  scopes.put(call, matchRecognizeScope);
2024 
2025  // parse input query
2026  SqlNode expr = call.getTableRef();
2027  SqlNode newExpr = registerFrom(usingScope, matchRecognizeScope, true, expr,
2028  expr, null, null, forceNullable, false);
2029  if (expr != newExpr) {
2030  call.setOperand(0, newExpr);
2031  }
2032  }
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 2051 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().

2055  {
2056  namespaces.put(ns.getNode(), ns);
2057  if (usingScope != null) {
2058  usingScope.addChild(ns, alias, forceNullable);
2059  }
2060  }

+ 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 3006 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().

3009  {
3010  SqlNode operand = call.operand(operandOrdinal);
3011  if (operand == null) {
3012  return;
3013  }
3014  if (operand.getKind().belongsTo(SqlKind.QUERY)
3015  && call.getOperator().argumentMustBeScalar(operandOrdinal)) {
3016  operand =
3017  SqlStdOperatorTable.SCALAR_QUERY.createCall(
3018  operand.getParserPosition(),
3019  operand);
3020  call.setOperand(operandOrdinal, operand);
3021  }
3022  registerSubQueries(parentScope, operand);
3023  }
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 2491 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().

2497  {
2498  Preconditions.checkArgument(usingScope == null || alias != null);
2499  registerQuery(
2500  parentScope,
2501  usingScope,
2502  node,
2503  enclosingNode,
2504  alias,
2505  forceNullable,
2506  true);
2507  }
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 2521 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.

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