Class SqlValidatorImpl

java.lang.Object
org.apache.calcite.sql.validate.SqlValidatorImpl
All Implemented Interfaces:
SqlValidator, SqlValidatorWithHints
Direct Known Subclasses:
CalciteSqlValidator, ContextSqlValidator, SqlAdvisorValidator

public class SqlValidatorImpl extends Object implements SqlValidatorWithHints
Default implementation of SqlValidator.
  • Field Details

  • Constructor Details

  • Method Details

    • getConformance

      public SqlConformance getConformance()
    • getCatalogReader

      @Pure public SqlValidatorCatalogReader getCatalogReader()
      Description copied from interface: SqlValidator
      Returns the catalog reader used by this validator.
      Specified by:
      getCatalogReader in interface SqlValidator
      Returns:
      catalog reader
    • getOperatorTable

      @Pure public SqlOperatorTable getOperatorTable()
      Description copied from interface: SqlValidator
      Returns the operator table used by this validator.
      Specified by:
      getOperatorTable in interface SqlValidator
      Returns:
      operator table
    • getTypeFactory

      @Pure public RelDataTypeFactory getTypeFactory()
      Description copied from interface: SqlValidator
      Returns the type factory used by this validator.
      Specified by:
      getTypeFactory in interface SqlValidator
      Returns:
      type factory
    • getUnknownType

      public RelDataType getUnknownType()
      Description copied from interface: SqlValidator
      Returns an object representing the "unknown" type.
      Specified by:
      getUnknownType in interface SqlValidator
      Returns:
      unknown type
    • getTimeFrameSet

      public TimeFrameSet getTimeFrameSet()
      Description copied from interface: SqlValidator
      Returns the set of allowed time frames.
      Specified by:
      getTimeFrameSet in interface SqlValidator
    • expandStar

      public SqlNodeList expandStar(SqlNodeList selectList, SqlSelect select, boolean includeSystemVars)
      Description copied from interface: SqlValidator
      Returns a list of expressions, with every occurrence of "*" or "TABLE.*" expanded.
      Specified by:
      expandStar in interface SqlValidator
      Parameters:
      selectList - Select clause to be expanded
      select - Query
      includeSystemVars - Whether to include system variables
      Returns:
      expanded select clause
    • declareCursor

      public void declareCursor(SqlSelect select, SqlValidatorScope parentScope)
      Description copied from interface: SqlValidator
      Declares a SELECT expression as a cursor.
      Specified by:
      declareCursor in interface SqlValidator
      Parameters:
      select - select expression associated with the cursor
      parentScope - scope of the parent query associated with the cursor
    • pushFunctionCall

      public void pushFunctionCall()
      Description copied from interface: SqlValidator
      Pushes a new instance of a function call on to a function call stack.
      Specified by:
      pushFunctionCall in interface SqlValidator
    • popFunctionCall

      public void popFunctionCall()
      Description copied from interface: SqlValidator
      Removes the topmost entry from the function call stack.
      Specified by:
      popFunctionCall in interface SqlValidator
    • getParentCursor

      public @Nullable String getParentCursor(String columnListParamName)
      Description copied from interface: SqlValidator
      Retrieves the name of the parent cursor referenced by a column list parameter.
      Specified by:
      getParentCursor in interface SqlValidator
      Parameters:
      columnListParamName - name of the column list parameter
      Returns:
      name of the parent cursor
    • usingNames

      public @Nullable List<String> usingNames(SqlJoin join)
      Returns the set of field names in the join condition specified by USING or implicitly by NATURAL, de-duplicated and in order.
    • validate

      public SqlNode validate(SqlNode topNode)
      Description copied from interface: SqlValidator
      Validates an expression tree. You can call this method multiple times, but not reentrantly.
      Specified by:
      validate in interface SqlValidator
      Parameters:
      topNode - top of expression tree to be validated
      Returns:
      validated tree (possibly rewritten)
    • lookupHints

      public List<SqlMoniker> lookupHints(SqlNode topNode, SqlParserPos pos)
      Description copied from interface: SqlValidatorWithHints
      Looks up completion hints for a syntactically correct SQL statement that has been parsed into an expression tree. (Note this should be called after SqlValidator.validate(org.apache.calcite.sql.SqlNode).
      Specified by:
      lookupHints in interface SqlValidatorWithHints
      Parameters:
      topNode - top of expression tree in which to lookup completion hints
      pos - indicates the position in the sql statement we want to get completion hints for. For example, "select a.ename, b.deptno from sales.emp a join sales.dept b "on a.deptno=b.deptno where empno=1"; setting pos to 'Line 1, Column 17' returns all the possible column names that can be selected from sales.dept table setting pos to 'Line 1, Column 31' returns all the possible table names in 'sales' schema
      Returns:
      an array of SqlMoniker (sql identifiers) that can fill in at the indicated position
    • lookupQualifiedName

      public @Nullable SqlMoniker lookupQualifiedName(SqlNode topNode, SqlParserPos pos)
      Description copied from interface: SqlValidatorWithHints
      Looks up the fully qualified name for a SqlIdentifier at a given Parser Position in a parsed expression tree Note: call this only after SqlValidator.validate(org.apache.calcite.sql.SqlNode) has been called.
      Specified by:
      lookupQualifiedName in interface SqlValidatorWithHints
      Parameters:
      topNode - top of expression tree in which to lookup the qualified name for the SqlIdentifier
      pos - indicates the position of the SqlIdentifier in the SQL statement we want to get the qualified name for
      Returns:
      a string of the fully qualified name of the SqlIdentifier if the Parser position represents a valid SqlIdentifier. Else return null
    • lookupNameCompletionHints

      public final void lookupNameCompletionHints(SqlValidatorScope scope, List<String> names, SqlParserPos pos, Collection<SqlMoniker> hintList)
      Populates a list of all the valid alternatives for an identifier.
      Parameters:
      scope - Validation scope
      names - Components of the identifier
      pos - position
      hintList - a list of valid options
    • validateParameterizedExpression

      public SqlNode validateParameterizedExpression(SqlNode topNode, Map<String,RelDataType> nameToTypeMap)
      Description copied from interface: SqlValidator
      Validates an expression tree. You can call this method multiple times, but not reentrantly.
      Specified by:
      validateParameterizedExpression in interface SqlValidator
      Parameters:
      topNode - top of expression tree to be validated
      nameToTypeMap - map of simple name to RelDataType; used to resolve SqlIdentifier references
      Returns:
      validated tree (possibly rewritten)
    • validateQuery

      public void validateQuery(SqlNode node, SqlValidatorScope scope, RelDataType targetRowType)
      Description copied from interface: SqlValidator
      Checks that a query is valid.

      Valid queries include:

      • SELECT statement,
      • set operation (UNION, INTERSECT, EXCEPT)
      • identifier (e.g. representing use of a table in a FROM clause)
      • query aliased with the AS operator
      Specified by:
      validateQuery in interface SqlValidator
      Parameters:
      node - Query node
      scope - Scope in which the query occurs
      targetRowType - Desired row type, must not be null, may be the data type 'unknown'.
    • validateNamespace

      protected void validateNamespace(SqlValidatorNamespace namespace, RelDataType targetRowType)
      Validates a namespace.
      Parameters:
      namespace - Namespace
      targetRowType - Desired row type, must not be null, may be the data type 'unknown'.
    • getEmptyScope

      public SqlValidatorScope getEmptyScope()
      Description copied from interface: SqlValidator
      Returns a scope that cannot see anything.
      Specified by:
      getEmptyScope in interface SqlValidator
    • getCursorScope

      public SqlValidatorScope getCursorScope(SqlSelect select)
    • getWhereScope

      public SqlValidatorScope getWhereScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns the scope that expressions in the WHERE and GROUP BY clause of this query should use. This scope consists of the tables in the FROM clause, and the enclosing scope.
      Specified by:
      getWhereScope in interface SqlValidator
      Parameters:
      select - Query
      Returns:
      naming scope of WHERE clause
    • getSelectScope

      public SqlValidatorScope getSelectScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns the appropriate scope for validating a particular clause of a SELECT statement.

      Consider

      SELECT *
       FROM foo
       WHERE EXISTS (
          SELECT deptno AS x
          FROM emp
             JOIN dept ON emp.deptno = dept.deptno
          WHERE emp.deptno = 5
          GROUP BY deptno
          ORDER BY x)

      What objects can be seen in each part of the sub-query?

      Specified by:
      getSelectScope in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      naming scope for SELECT statement
    • getMeasureScope

      public SqlValidatorScope getMeasureScope(SqlSelect select)
      Specified by:
      getMeasureScope in interface SqlValidator
    • getRawSelectScope

      public @Nullable SelectScope getRawSelectScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns the scope for resolving the SELECT, GROUP BY and HAVING clauses. Always a SelectScope; if this is an aggregation query, the AggregatingScope is stripped away.
      Specified by:
      getRawSelectScope in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      naming scope for SELECT statement, sans any aggregating scope
    • getHavingScope

      public SqlValidatorScope getHavingScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns a scope containing the objects visible from the HAVING clause of a query.
      Specified by:
      getHavingScope in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      naming scope for HAVING clause
    • getGroupScope

      public SqlValidatorScope getGroupScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns a scope containing the objects visible from the GROUP BY clause of a query.
      Specified by:
      getGroupScope in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      naming scope for GROUP BY clause
    • getFromScope

      public SqlValidatorScope getFromScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns a scope containing the objects visible from the FROM clause of a query.
      Specified by:
      getFromScope in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      naming scope for FROM clause
    • getOrderScope

      public SqlValidatorScope getOrderScope(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns the scope that expressions in the SELECT and HAVING clause of this query should use. This scope consists of the FROM clause and the enclosing scope. If the query is aggregating, only columns in the GROUP BY clause may be used.
      Specified by:
      getOrderScope in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      naming scope for ORDER BY clause
    • getMatchRecognizeScope

      public SqlValidatorScope getMatchRecognizeScope(SqlMatchRecognize node)
      Description copied from interface: SqlValidator
      Returns a scope match recognize clause.
      Specified by:
      getMatchRecognizeScope in interface SqlValidator
      Parameters:
      node - Match recognize
      Returns:
      naming scope for Match recognize clause
    • getLambdaScope

      public SqlValidatorScope getLambdaScope(SqlLambda node)
      Description copied from interface: SqlValidator
      Returns the lambda expression scope.
      Specified by:
      getLambdaScope in interface SqlValidator
      Parameters:
      node - Lambda expression
      Returns:
      naming scope for lambda expression
    • getJoinScope

      public SqlValidatorScope getJoinScope(SqlNode node)
      Description copied from interface: SqlValidator
      Returns a scope containing the objects visible from the ON and USING sections of a JOIN clause.
      Specified by:
      getJoinScope in interface SqlValidator
      Parameters:
      node - The item in the FROM clause which contains the ON or USING expression
      Returns:
      naming scope for JOIN clause
      See Also:
    • getOverScope

      public SqlValidatorScope getOverScope(SqlNode node)
      Description copied from interface: SqlValidator
      Returns the scope of an OVER or VALUES node.
      Specified by:
      getOverScope in interface SqlValidator
      Parameters:
      node - Node
      Returns:
      Scope
    • getWithScope

      public SqlValidatorScope getWithScope(SqlNode withItem)
      Specified by:
      getWithScope in interface SqlValidator
    • getNamespace

      public @Nullable SqlValidatorNamespace getNamespace(SqlNode node)
      Description copied from interface: SqlValidator
      Finds the namespace corresponding to a given node.

      For example, in the query SELECT * FROM (SELECT * FROM t), t1 AS alias, the both items in the FROM clause have a corresponding namespace.

      Specified by:
      getNamespace in interface SqlValidator
      Parameters:
      node - Parse tree node
      Returns:
      namespace of node
    • performUnconditionalRewrites

      protected @PolyNull SqlNode performUnconditionalRewrites(@PolyNull SqlNode node, boolean underFrom)
      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.

      Returns null if and only if the original expression is null.

      Parameters:
      node - expression to be rewritten
      underFrom - whether node appears directly under a FROM clause
      Returns:
      rewritten expression, or null if the original expression is null
    • getSelfJoinExprForUpdate

      protected @Nullable SqlNode getSelfJoinExprForUpdate(SqlNode table, String alias)
      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:
      table - identifier for table being updated
      alias - alias to use for qualifying columns in expression, or null for unqualified references; if this is equal to "SYS$SRC", 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
    • createSourceSelectForUpdate

      protected SqlSelect createSourceSelectForUpdate(SqlUpdate call)
      Creates the SELECT statement that putatively feeds rows into an UPDATE statement to be updated.
      Parameters:
      call - Call to the UPDATE operator
      Returns:
      select statement
    • createSourceSelectForDelete

      protected SqlSelect createSourceSelectForDelete(SqlDelete call)
      Creates the SELECT statement that putatively feeds rows into a DELETE statement to be deleted.
      Parameters:
      call - Call to the DELETE operator
      Returns:
      select statement
    • getValidatedNodeType

      public RelDataType getValidatedNodeType(SqlNode node)
      Description copied from interface: SqlValidator
      Returns the type assigned to a node by validation.
      Specified by:
      getValidatedNodeType in interface SqlValidator
      Parameters:
      node - the node of interest
      Returns:
      validated type, never null
    • getValidatedNodeTypeIfKnown

      public @Nullable RelDataType getValidatedNodeTypeIfKnown(SqlNode node)
      Description copied from interface: SqlValidator
      Returns the type assigned to a node by validation, or null if unknown. This allows for queries against nodes such as aliases, which have no type of their own. If you want to assert that the node of interest must have a type, use SqlValidator.getValidatedNodeType(org.apache.calcite.sql.SqlNode) instead.
      Specified by:
      getValidatedNodeTypeIfKnown in interface SqlValidator
      Parameters:
      node - the node of interest
      Returns:
      validated type, or null if unknown or not applicable
    • getValidatedOperandTypes

      public @Nullable List<RelDataType> getValidatedOperandTypes(SqlCall call)
      Description copied from interface: SqlValidator
      Returns the types of a call's operands.

      Returns null if the call has not been validated, or if the operands' types do not differ from their types as expressions.

      This method is most useful when some of the operands are of type ANY, or if they need to be coerced to be consistent with other operands, or with the needs of the function.

      Specified by:
      getValidatedOperandTypes in interface SqlValidator
      Parameters:
      call - Call
      Returns:
      List of operands' types, or null if not known or 'obvious'
    • setValidatedNodeType

      public final void setValidatedNodeType(SqlNode node, RelDataType type)
      Saves the type of a SqlNode, now that it has been validated.

      Unlike the base class method, this method is not deprecated. It is available from within Calcite, but is not part of the public API.

      Specified by:
      setValidatedNodeType in interface SqlValidator
      Parameters:
      node - A SQL parse tree node, never null
      type - Its type; must not be null
    • removeValidatedNodeType

      public void removeValidatedNodeType(SqlNode node)
      Description copied from interface: SqlValidator
      Removes a node from the set of validated nodes.
      Specified by:
      removeValidatedNodeType in interface SqlValidator
      Parameters:
      node - node to be removed
    • makeNullaryCall

      public @Nullable SqlCall makeNullaryCall(SqlIdentifier id)
      Description copied from interface: SqlValidator
      If an identifier is a legitimate call to a function that has no arguments and requires no parentheses (for example "CURRENT_USER"), returns a call to that function, otherwise returns null.
      Specified by:
      makeNullaryCall in interface SqlValidator
    • deriveType

      public RelDataType deriveType(SqlValidatorScope scope, SqlNode expr)
      Description copied from interface: SqlValidator
      Derives the type of a node in a given scope. If the type has already been inferred, returns the previous type.
      Specified by:
      deriveType in interface SqlValidator
      Parameters:
      scope - Syntactic scope
      expr - Parse tree node
      Returns:
      Type of the SqlNode. Should never return NULL
    • deriveConstructorType

      public RelDataType deriveConstructorType(SqlValidatorScope scope, SqlCall call, SqlFunction unresolvedConstructor, @Nullable SqlFunction resolvedConstructor, List<RelDataType> argTypes)
      Description copied from interface: SqlValidator
      Derives the type of a constructor.
      Specified by:
      deriveConstructorType in interface SqlValidator
      Parameters:
      scope - Scope
      call - Call
      unresolvedConstructor - TODO
      resolvedConstructor - TODO
      argTypes - Types of arguments
      Returns:
      Resolved type of constructor
    • handleUnresolvedFunction

      public CalciteException handleUnresolvedFunction(SqlCall call, SqlOperator unresolvedFunction, List<RelDataType> argTypes, @Nullable List<String> argNames)
      Description copied from interface: SqlValidator
      Handles a call to a function which cannot be resolved. Returns an appropriately descriptive error, which caller must throw.
      Specified by:
      handleUnresolvedFunction in interface SqlValidator
      Parameters:
      call - Call
      unresolvedFunction - Overloaded function which is the target of the call
      argTypes - Types of arguments
      argNames - Names of arguments, or null if call by position
    • inferUnknownTypes

      protected void inferUnknownTypes(RelDataType inferredType, SqlValidatorScope scope, SqlNode node)
    • addToSelectList

      protected void addToSelectList(List<SqlNode> list, Set<String> aliases, List<Map.Entry<String,RelDataType>> fieldList, SqlNode exp, SelectScope scope, boolean includeSystemVars)
      Adds an expression to a select list, ensuring that its alias does not clash with any existing expressions on the list.
    • deriveAlias

      public @Nullable String deriveAlias(SqlNode node, int ordinal)
      Description copied from interface: SqlValidator
      Derives an alias for an expression. If no alias can be derived, returns null if ordinal is less than zero, otherwise generates an alias EXPR$ordinal.
      Specified by:
      deriveAlias in interface SqlValidator
      Parameters:
      node - Expression
      ordinal - Ordinal of expression
      Returns:
      derived alias, or null if no alias can be derived and ordinal is less than zero
    • shouldAllowIntermediateOrderBy

      protected boolean shouldAllowIntermediateOrderBy()
    • createMatchRecognizeNameSpace

      protected MatchRecognizeNamespace createMatchRecognizeNameSpace(SqlMatchRecognize call, SqlNode enclosingNode)
    • createPivotNameSpace

      protected PivotNamespace createPivotNameSpace(SqlPivot call, SqlNode enclosingNode)
    • createUnpivotNameSpace

      protected UnpivotNamespace createUnpivotNameSpace(SqlUnpivot call, SqlNode enclosingNode)
    • registerNamespace

      protected void registerNamespace(@Nullable SqlValidatorScope usingScope, @Nullable String alias, SqlValidatorNamespace ns, boolean forceNullable)
      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:
      usingScope - Parent scope (which will want to look for things in this namespace)
      alias - Alias by which parent will refer to this namespace
      ns - Namespace
      forceNullable - Whether to force the type of namespace to be nullable
    • shouldAllowOverRelation

      protected boolean shouldAllowOverRelation()
    • createSelectNamespace

      protected SelectNamespace createSelectNamespace(SqlSelect select, SqlNode enclosingNode)
      Creates a namespace for a SELECT node. Derived class may override this factory method.
      Parameters:
      select - Select node
      enclosingNode - Enclosing node
      Returns:
      Select namespace
    • createSetopNamespace

      protected SetopNamespace createSetopNamespace(SqlCall call, SqlNode enclosingNode)
      Creates a namespace for a set operation (UNION, INTERSECT, or EXCEPT). Derived class may override this factory method.
      Parameters:
      call - Call to set operation
      enclosingNode - Enclosing node
      Returns:
      Set operation namespace
    • registerQuery

      protected void registerQuery(SqlValidatorScope parentScope, @Nullable SqlValidatorScope usingScope, SqlNode node, SqlNode enclosingNode, @Nullable String alias, boolean forceNullable)
      Registers a query in a parent scope.
      Parameters:
      parentScope - Parent scope which this scope turns to in order to resolve objects
      usingScope - Scope whose child list this scope should add itself to
      node - Query node
      alias - Name of this query within its parent. Must be specified if usingScope != null
    • isAggregate

      public boolean isAggregate(SqlSelect select)
      Description copied from interface: SqlValidator
      Returns whether a SELECT statement is an aggregation. Criteria are: (1) contains GROUP BY, or (2) contains HAVING, or (3) SELECT or ORDER BY clause contains aggregate functions. (Windowed aggregate functions, such as SUM(x) OVER w, don't count.)
      Specified by:
      isAggregate in interface SqlValidator
      Parameters:
      select - SELECT statement
      Returns:
      whether SELECT statement is an aggregation
    • isNestedAggregateWindow

      protected boolean isNestedAggregateWindow(SqlNode node)
    • isOverAggregateWindow

      protected boolean isOverAggregateWindow(SqlNode node)
    • getAggregate

      protected @Nullable SqlNode getAggregate(SqlSelect select)
      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.

    • isAggregate

      @Deprecated public boolean isAggregate(SqlNode selectNode)
      Deprecated.
      Description copied from interface: SqlValidator
      Returns whether a select list expression is an aggregate function.
      Specified by:
      isAggregate in interface SqlValidator
      Parameters:
      selectNode - Expression in SELECT clause
      Returns:
      whether expression is an aggregate function
    • validateIdentifier

      public void validateIdentifier(SqlIdentifier id, SqlValidatorScope scope)
      Description copied from interface: SqlValidator
      Resolves an identifier to a fully-qualified name.
      Specified by:
      validateIdentifier in interface SqlValidator
      Parameters:
      id - Identifier
      scope - Naming scope
    • validateLiteral

      public void validateLiteral(SqlLiteral literal)
      Description copied from interface: SqlValidator
      Validates a literal.
      Specified by:
      validateLiteral in interface SqlValidator
      Parameters:
      literal - Literal
    • validateIntervalQualifier

      public void validateIntervalQualifier(SqlIntervalQualifier qualifier)
      Description copied from interface: SqlValidator
      Specified by:
      validateIntervalQualifier in interface SqlValidator
      Parameters:
      qualifier - Interval qualifier
    • validateTimeFrame

      public TimeFrame validateTimeFrame(SqlIntervalQualifier qualifier)
      Description copied from interface: SqlValidator
      Validates a time frame.

      A time frame is either a built-in time frame based on a time unit such as TimeUnitRange.HOUR, or is a custom time frame represented by a name in SqlIntervalQualifier.timeFrameName. A custom time frame is validated against SqlValidator.getTimeFrameSet().

      Returns a time frame, or throws.

      Specified by:
      validateTimeFrame in interface SqlValidator
    • validateFrom

      protected void validateFrom(SqlNode node, RelDataType targetRowType, SqlValidatorScope scope)
      Validates the FROM clause of a query, or (recursively) a child node of the FROM clause: AS, OVER, JOIN, VALUES, or sub-query.
      Parameters:
      node - Node in FROM clause, typically a table or derived table
      targetRowType - Desired row type of this expression, or unknownType if not fussy. Must not be null.
      scope - Scope
    • validateTableFunction

      protected void validateTableFunction(SqlCall node, SqlValidatorScope scope, RelDataType targetRowType)
    • validateOver

      protected void validateOver(SqlCall call, SqlValidatorScope scope)
    • validateUnnest

      protected void validateUnnest(SqlCall call, SqlValidatorScope scope, RelDataType targetRowType)
    • validateJoin

      protected void validateJoin(SqlJoin join, SqlValidatorScope scope)
    • validateSelect

      protected void validateSelect(SqlSelect select, RelDataType targetRowType)
      Validates a SELECT statement.
      Parameters:
      select - Select statement
      targetRowType - Desired row type, must not be null, may be the data type 'unknown'.
    • validateModality

      public boolean validateModality(SqlSelect select, SqlModality modality, boolean fail)
      Description copied from interface: SqlValidator
      Validates that a query is capable of producing a return of given modality (relational or streaming).
      Specified by:
      validateModality in interface SqlValidator
      Parameters:
      select - Query
      modality - Modality (streaming or relational)
      fail - Whether to throw a user error if does not support required modality
      Returns:
      whether query supports the given modality
    • validateWindowClause

      protected void validateWindowClause(SqlSelect select)
    • validateQualifyClause

      protected void validateQualifyClause(SqlSelect select)
    • validateWith

      public void validateWith(SqlWith with, SqlValidatorScope scope)
      Specified by:
      validateWith in interface SqlValidator
    • validateWithItem

      public void validateWithItem(SqlWithItem withItem)
      Specified by:
      validateWithItem in interface SqlValidator
    • validateSequenceValue

      public void validateSequenceValue(SqlValidatorScope scope, SqlIdentifier id)
      Specified by:
      validateSequenceValue in interface SqlValidator
    • getTypeCoercion

      public TypeCoercion getTypeCoercion()
      Description copied from interface: SqlValidator
      Get the type coercion instance.
      Specified by:
      getTypeCoercion in interface SqlValidator
    • config

      public SqlValidator.Config config()
      Description copied from interface: SqlValidator
      Returns the config of the validator.
      Specified by:
      config in interface SqlValidator
    • transform

      public SqlValidator transform(UnaryOperator<SqlValidator.Config> transform)
      Description copied from interface: SqlValidator
      Returns this SqlValidator, with the same state, applying a transform to the config.

      This is mainly used for tests, otherwise constructs a SqlValidator.Config directly through the constructor.

      Specified by:
      transform in interface SqlValidator
    • validateOrderList

      protected void validateOrderList(SqlSelect select)
      Validates the ORDER BY clause of a SELECT statement.
      Parameters:
      select - Select statement
    • expandOrderExpr

      public SqlNode expandOrderExpr(SqlSelect select, SqlNode orderExpr)
      Description copied from interface: SqlValidator
      Expands an expression in the ORDER BY clause into an expression with the same semantics as expressions in the SELECT clause.

      This is made necessary by a couple of dialect 'features':

      • ordinal expressions: In "SELECT x, y FROM t ORDER BY 2", the expression "2" is shorthand for the 2nd item in the select clause, namely "y".
      • alias references: In "SELECT x AS a, y FROM t ORDER BY a", the expression "a" is shorthand for the item in the select clause whose alias is "a"
      Specified by:
      expandOrderExpr in interface SqlValidator
      Parameters:
      select - Select statement which contains ORDER BY
      orderExpr - Expression in the ORDER BY clause.
      Returns:
      Expression translated into SELECT clause semantics
    • validateGroupClause

      protected void validateGroupClause(SqlSelect select)
      Validates the GROUP BY clause of a SELECT statement. This method is called even if no GROUP BY clause is present.
    • validateWhereClause

      protected void validateWhereClause(SqlSelect select)
    • validateWhereOrOn

      protected void validateWhereOrOn(SqlValidatorScope scope, SqlNode condition, String clause)
    • validateHavingClause

      protected void validateHavingClause(SqlSelect select)
    • validateSelectList

      protected RelDataType validateSelectList(SqlNodeList selectItems, SqlSelect select, RelDataType targetRowType)
    • createTargetRowType

      protected RelDataType createTargetRowType(SqlValidatorTable table, @Nullable SqlNodeList targetColumnList, boolean append, @Nullable SqlIdentifier targetTableAlias)
      Derives a row-type for INSERT and UPDATE operations.
      Parameters:
      table - Target table for INSERT/UPDATE
      targetColumnList - List of target columns, or null if not specified
      append - Whether to append fields to those in baseRowType
      targetTableAlias - Target table alias, or null if not specified
      Returns:
      Rowtype
    • validateInsert

      public void validateInsert(SqlInsert insert)
      Description copied from interface: SqlValidator
      Validates an INSERT statement.
      Specified by:
      validateInsert in interface SqlValidator
      Parameters:
      insert - INSERT statement
    • getLogicalTargetRowType

      protected RelDataType getLogicalTargetRowType(RelDataType targetRowType, SqlInsert insert)
    • getLogicalSourceRowType

      protected RelDataType getLogicalSourceRowType(RelDataType sourceRowType, SqlInsert insert)
    • checkTypeAssignment

      protected void checkTypeAssignment(@Nullable SqlValidatorScope sourceScope, SqlValidatorTable table, RelDataType sourceRowType, RelDataType targetRowType, SqlNode query)
      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:
      sourceScope - Scope of query source which is used to infer node type
      table - Target table
      sourceRowType - Source row type
      targetRowType - Target row type, it should either contain all the virtual columns (can not insert into) or exclude all the virtual columns
      query - The query
    • validateDelete

      public void validateDelete(SqlDelete call)
      Description copied from interface: SqlValidator
      Validates a DELETE statement.
      Specified by:
      validateDelete in interface SqlValidator
      Parameters:
      call - DELETE statement
    • validateUpdate

      public void validateUpdate(SqlUpdate call)
      Description copied from interface: SqlValidator
      Validates an UPDATE statement.
      Specified by:
      validateUpdate in interface SqlValidator
      Parameters:
      call - UPDATE statement
    • validateMerge

      public void validateMerge(SqlMerge call)
      Description copied from interface: SqlValidator
      Validates a MERGE statement.
      Specified by:
      validateMerge in interface SqlValidator
      Parameters:
      call - MERGE statement
    • validateValues

      protected void validateValues(SqlCall node, RelDataType targetRowType, SqlValidatorScope scope)
      Validates a VALUES clause.
      Parameters:
      node - Values clause
      targetRowType - Row type which expression must conform to
      scope - Scope within which clause occurs
    • validateDataType

      public void validateDataType(SqlDataTypeSpec dataType)
      Description copied from interface: SqlValidator
      Validates a data type expression.
      Specified by:
      validateDataType in interface SqlValidator
      Parameters:
      dataType - Data type
    • validateDynamicParam

      public void validateDynamicParam(SqlDynamicParam dynamicParam)
      Description copied from interface: SqlValidator
      Validates a dynamic parameter.
      Specified by:
      validateDynamicParam in interface SqlValidator
      Parameters:
      dynamicParam - Dynamic parameter
    • getValidationErrorFunction

      public org.apache.calcite.sql.validate.SqlValidatorImpl.ValidationErrorFunction getValidationErrorFunction()
    • newValidationError

      public CalciteContextException newValidationError(SqlNode node, org.apache.calcite.runtime.Resources.ExInst<SqlValidatorException> e)
      Description copied from interface: SqlValidator
      Adds "line x, column y" context to a validator exception.

      Note that the input exception is checked (it derives from Exception) and the output exception is unchecked (it derives from RuntimeException). This is intentional -- it should remind code authors to provide context for their validation errors.

      Specified by:
      newValidationError in interface SqlValidator
      Parameters:
      node - The place where the exception occurred, not null
      e - The validation error
      Returns:
      Exception containing positional information, never null
    • getWindowByName

      protected SqlWindow getWindowByName(SqlIdentifier id, SqlValidatorScope scope)
    • resolveWindow

      public SqlWindow resolveWindow(SqlNode windowOrRef, SqlValidatorScope scope)
      Description copied from interface: SqlValidator
      Converts a window specification or window name into a fully-resolved window specification. For example, in SELECT sum(x) OVER (PARTITION BY x ORDER BY y), sum(y) OVER w1, sum(z) OVER (w ORDER BY y) FROM t WINDOW w AS (PARTITION BY x) all aggregations have the same resolved window specification (PARTITION BY x ORDER BY y).
      Specified by:
      resolveWindow in interface SqlValidator
      Parameters:
      windowOrRef - Either the name of a window (a SqlIdentifier) or a window specification (a SqlWindow).
      scope - Scope in which to resolve window names
      Returns:
      A window
    • getOriginal

      public SqlNode getOriginal(SqlNode expr)
    • setOriginal

      public void setOriginal(SqlNode expr, SqlNode original)
    • validateWindow

      public void validateWindow(SqlNode windowOrId, SqlValidatorScope scope, @Nullable SqlCall call)
      Description copied from interface: SqlValidator
      Validates the right-hand side of an OVER expression. It might be either an identifier referencing a window, or an inline window specification.
      Specified by:
      validateWindow in interface SqlValidator
      Parameters:
      windowOrId - SqlNode that can be either SqlWindow with all the components of a window spec or a SqlIdentifier with the name of a window spec.
      scope - Naming scope
      call - the SqlNode if a function call if the window is attached to one.
    • validateLambda

      public void validateLambda(SqlLambda lambdaExpr)
      Description copied from interface: SqlValidator
      Validates a lambda expression. lambda expression will be validated twice during the validation process. The first time is validate lambda expression namespace, the second time is when validating higher order function operands type check.
      Specified by:
      validateLambda in interface SqlValidator
      Parameters:
      lambdaExpr - Lambda expression
    • validateMatchRecognize

      public void validateMatchRecognize(SqlCall call)
      Description copied from interface: SqlValidator
      Validates a MATCH_RECOGNIZE clause.
      Specified by:
      validateMatchRecognize in interface SqlValidator
      Parameters:
      call - MATCH_RECOGNIZE clause
    • validatePivot

      public void validatePivot(SqlPivot pivot)
    • validateUnpivot

      public void validateUnpivot(SqlUnpivot unpivot)
    • validateAggregateParams

      public void validateAggregateParams(SqlCall aggCall, @Nullable SqlNode filter, @Nullable SqlNodeList distinctList, @Nullable SqlNodeList orderList, SqlValidatorScope scope)
      Description copied from interface: SqlValidator
      Validates parameters for aggregate function.
      Specified by:
      validateAggregateParams in interface SqlValidator
      Parameters:
      aggCall - Call to aggregate function
      filter - Filter (FILTER (WHERE) clause), or null
      distinctList - Distinct specification (WITHIN DISTINCT clause), or null
      orderList - Ordering specification (WITHIN GROUP clause), or null
      scope - Syntactic scope
    • validateCall

      public void validateCall(SqlCall call, SqlValidatorScope scope)
      Description copied from interface: SqlValidator
      Validates a call to an operator.
      Specified by:
      validateCall in interface SqlValidator
      Parameters:
      call - Operator call
      scope - Naming scope
    • validateFeature

      protected void validateFeature(Feature feature, SqlParserPos context)
      Validates that a particular feature is enabled. By default, all features are enabled; subclasses may override this method to be more discriminating.
      Parameters:
      feature - feature being used, represented as a resource instance
      context - parser position context for error reporting, or null if
    • resolveLiteral

      public SqlLiteral resolveLiteral(SqlLiteral literal)
      Description copied from interface: SqlValidator
      Resolves a literal.

      Usually returns the literal unchanged, but if the literal is of type SqlTypeName.UNKNOWN looks up its type and converts to the appropriate literal subclass.

      Specified by:
      resolveLiteral in interface SqlValidator
    • expandSelectExpr

      public SqlNode expandSelectExpr(SqlNode expr, SelectScope scope, SqlSelect select)
    • expand

      public SqlNode expand(SqlNode expr, SqlValidatorScope scope)
      Description copied from interface: SqlValidator
      Expands an expression.
      Specified by:
      expand in interface SqlValidator
      Parameters:
      expr - Expression
      scope - Scope
      Returns:
      Expanded expression
    • extendedExpandGroupBy

      public SqlNode extendedExpandGroupBy(SqlNode expr, SqlValidatorScope scope, SqlSelect select)
    • isSystemField

      public boolean isSystemField(RelDataTypeField field)
      Description copied from interface: SqlValidator
      Returns whether a field is a system field. Such fields may have particular properties such as sortedness and nullability.

      In the default implementation, always returns false.

      Specified by:
      isSystemField in interface SqlValidator
      Parameters:
      field - Field
      Returns:
      whether field is a system field
    • getFieldOrigins

      public List<@Nullable List<String>> getFieldOrigins(SqlNode sqlQuery)
      Description copied from interface: SqlValidator
      Returns a description of how each field in the row type maps to a catalog, schema, table and column in the schema.

      The returned list is never null, and has one element for each field in the row type. Each element is a list of four elements (catalog, schema, table, column), or may be null if the column is an expression.

      Specified by:
      getFieldOrigins in interface SqlValidator
      Parameters:
      sqlQuery - Query
      Returns:
      Description of how each field in the row type maps to a schema object
    • getParameterRowType

      public RelDataType getParameterRowType(SqlNode sqlQuery)
      Description copied from interface: SqlValidator
      Returns a record type that contains the name and type of each parameter. Returns a record type with no fields if there are no parameters.
      Specified by:
      getParameterRowType in interface SqlValidator
      Parameters:
      sqlQuery - Query
      Returns:
      Record type