Class SqlRowOperator

java.lang.Object
org.apache.calcite.sql.SqlOperator
org.apache.calcite.sql.SqlSpecialOperator
org.apache.calcite.sql.fun.SqlRowOperator

public class SqlRowOperator extends org.apache.calcite.sql.SqlSpecialOperator
Copied to keep null semantics of table api and sql in sync.

There are differences following:

1. The return value about R IS NULL and R IS NOT NULL.

At the same time SQL standard says that the next about `ROW`:

  • The value of R IS NULL is:
    • If the value of every field of V is the null value, then True.
    • Otherwise, False.
  • The value of R IS NOT NULL is:
    • If the value of no field of V is the null value, then True.
    • Otherwise, False.

Calcite applies that logic since CALCITE-3627 (1.30.0+).

  • Thus, with Calcite 1.30.0+
    • SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NOT NULL; -- returns FALSE
    • SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NULL; -- returns TRUE.
  • With Flink and Calcite before 1.30.0 (current behavior of this class)
    • SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NOT NULL; -- returns TRUE
    • SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NULL; -- returns FALSE

Once Flink applies same logic for both table api and sql, this first changes should be removed.

2. It uses StructKind.PEEK_FIELDS_NO_EXPAND with a nested struct type (Flink [[RowType]]).

See more at LogicalRelDataTypeConverter and org.apache.flink.table.planner.calcite.FlinkTypeFactory.

Changed lines

  1. Line 106 ~ 137
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.calcite.sql.SqlSpecialOperator

    org.apache.calcite.sql.SqlSpecialOperator.ReduceResult, org.apache.calcite.sql.SqlSpecialOperator.TokenSequence
  • Field Summary

    Fields inherited from class org.apache.calcite.sql.SqlOperator

    kind, MDX_PRECEDENCE, NL
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.calcite.rel.type.RelDataType
    inferReturnType(org.apache.calcite.sql.SqlOperatorBinding opBinding)
     
    boolean
     
    void
    unparse(org.apache.calcite.sql.SqlWriter writer, org.apache.calcite.sql.SqlCall call, int leftPrec, int rightPrec)
     

    Methods inherited from class org.apache.calcite.sql.SqlSpecialOperator

    getSyntax, reduceExpr

    Methods inherited from class org.apache.calcite.sql.SqlOperator

    acceptCall, acceptCall, adjustType, allowsFraming, argumentMustBeScalar, checkOperandCount, checkOperandTypes, constructArgNameList, constructArgTypeList, constructOperandList, createCall, createCall, createCall, createCall, createCall, createCall, createCall, deriveOperandType, deriveType, equals, getAllowedSignatures, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getMonotonicity, getName, getNameAsId, getOperandCountRange, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, getSignatureTemplate, getStrongPolicyInference, hashCode, inferReturnType, isAggregator, isDeterministic, isDynamicFunction, isGroup, isGroupAuxiliary, isName, isSymmetrical, leftPrec, not, preValidateCall, requiresOrder, requiresOver, reverse, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateCall, validateOperands, validRexOperands

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SqlRowOperator

      public SqlRowOperator(String name)
  • Method Details

    • inferReturnType

      public org.apache.calcite.rel.type.RelDataType inferReturnType(org.apache.calcite.sql.SqlOperatorBinding opBinding)
      Overrides:
      inferReturnType in class org.apache.calcite.sql.SqlOperator
    • unparse

      public void unparse(org.apache.calcite.sql.SqlWriter writer, org.apache.calcite.sql.SqlCall call, int leftPrec, int rightPrec)
      Overrides:
      unparse in class org.apache.calcite.sql.SqlOperator
    • requiresDecimalExpansion

      public boolean requiresDecimalExpansion()
      Overrides:
      requiresDecimalExpansion in class org.apache.calcite.sql.SqlOperator