Class SqlOperatorBinding

java.lang.Object
org.apache.calcite.sql.SqlOperatorBinding
Direct Known Subclasses:
Aggregate.AggCallBinding, ExplicitOperatorBinding, RexCallBinding, SqlCallBinding

public abstract class SqlOperatorBinding extends Object
SqlOperatorBinding represents the binding of an SqlOperator to actual operands, along with any additional information required to validate those operands if needed.
  • Field Details

  • Constructor Details

    • SqlOperatorBinding

      protected SqlOperatorBinding(RelDataTypeFactory typeFactory, SqlOperator sqlOperator)
      Creates a SqlOperatorBinding.
      Parameters:
      typeFactory - Type factory
      sqlOperator - Operator which is subject of this call
  • Method Details

    • getGroupCount

      public int getGroupCount()
      If the operator call occurs in an aggregate query, returns the number of columns in the GROUP BY clause. For example, for "SELECT count(*) FROM emp GROUP BY deptno, gender", returns 2.

      Returns 0 if the query is implicitly "GROUP BY ()" because of an aggregate expression. For example, "SELECT sum(sal) FROM emp".

      Returns -1 if the query is not an aggregate query.

    • hasFilter

      public boolean hasFilter()
      Returns whether the operator is an aggregate function with a filter.
    • getOperator

      public SqlOperator getOperator()
      Returns the bound operator.
    • getTypeFactory

      public RelDataTypeFactory getTypeFactory()
      Returns the factory for type creation.
    • getStringLiteralOperand

      @Deprecated public @Nullable String getStringLiteralOperand(int ordinal)
      Deprecated.
      Gets the string value of a string literal operand.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      Returns:
      string value
    • getIntLiteralOperand

      @Deprecated public int getIntLiteralOperand(int ordinal)
      Deprecated.
      Gets the integer value of a numeric literal operand.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      Returns:
      integer value
    • getOperandLiteralValue

      public <T> @Nullable T getOperandLiteralValue(int ordinal, Class<T> clazz)
      Gets the value of a literal operand.

      Cases:

      • If the operand is not a literal, the value is null.
      • If the operand is a string literal, the value will be of type NlsString.
      • If the operand is a numeric literal, the value will be of type BigDecimal.
      • If the operand is an interval qualifier, the value will be of type SqlIntervalQualifier
      • Otherwise the type is undefined, and the value may be null.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      clazz - Desired valued type
      Returns:
      value of operand
    • getOperandLiteralValue

      public @Nullable Object getOperandLiteralValue(int ordinal, RelDataType type)
      Gets the value of a literal operand as a Calcite type.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      type - Desired valued type
      Returns:
      value of operand
    • getOperandLiteralValue

      @Deprecated public @Nullable Comparable getOperandLiteralValue(int ordinal)
      Deprecated.
    • isOperandNull

      public boolean isOperandNull(int ordinal, boolean allowCast)
      Determines whether a bound operand is NULL.

      This is only relevant for SQL validation.

      Parameters:
      ordinal - zero-based ordinal of operand of interest
      allowCast - whether to regard CAST(constant) as a constant
      Returns:
      whether operand is null; false for everything except SQL validation
    • isOperandLiteral

      public boolean isOperandLiteral(int ordinal, boolean allowCast)
      Determines whether an operand is a literal.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      allowCast - whether to regard CAST(literal) as a literal
      Returns:
      whether operand is literal
    • isOperandTimeFrame

      public boolean isOperandTimeFrame(int ordinal)
      Returns whether an operand is a time frame.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      Returns:
      whether operand is a time frame
    • getOperandCount

      public abstract int getOperandCount()
      Returns the number of bound operands. Includes pre-operands and regular operands.
    • getPreOperandCount

      public int getPreOperandCount()
      Returns the number of pre-operands. Zero except for a few aggregate functions.
    • getOperandType

      public abstract RelDataType getOperandType(int ordinal)
      Gets the type of a bound operand.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      Returns:
      bound operand type
    • getOperandMonotonicity

      public SqlMonotonicity getOperandMonotonicity(int ordinal)
      Gets the monotonicity of a bound operand.
      Parameters:
      ordinal - zero-based ordinal of operand of interest
      Returns:
      monotonicity of operand
    • getCollationType

      public RelDataType getCollationType()
      Returns the collation type.
    • collectOperandTypes

      public List<RelDataType> collectOperandTypes()
      Collects the types of the bound operands into a list.
      Returns:
      collected list
    • getCursorOperand

      public @Nullable RelDataType getCursorOperand(int ordinal)
      Returns the rowtype of the ordinalth operand, which is a cursor.

      This is only implemented for SqlCallBinding.

      Parameters:
      ordinal - Ordinal of the operand
      Returns:
      Rowtype of the query underlying the cursor
    • getColumnListParamInfo

      public @Nullable String getColumnListParamInfo(int ordinal, String paramName, List<String> columnList)
      Retrieves information about a column list parameter.
      Parameters:
      ordinal - ordinal position of the column list parameter
      paramName - name of the column list parameter
      columnList - returns a list of the column names that are referenced in the column list parameter
      Returns:
      the name of the parent cursor referenced by the column list parameter if it is a column list parameter; otherwise, null is returned
    • newError

      public abstract CalciteException newError(org.apache.calcite.runtime.Resources.ExInst<SqlValidatorException> e)
      Wraps a validation error with context appropriate to this operator call.
      Parameters:
      e - Validation error, not null
      Returns:
      Error wrapped, if possible, with positional information
    • transform

      public SqlOperatorBinding transform(SqlTypeTransform typeTransform)
      Returns an operator binding equivalent that is equivalent to this except that a transform has been applied to each operand type.