Class FlinkRexBuilder

java.lang.Object
org.apache.calcite.rex.RexBuilder
org.apache.flink.table.planner.calcite.FlinkRexBuilder

public final class FlinkRexBuilder extends org.apache.calcite.rex.RexBuilder
A slim extension over a RexBuilder. See the overridden methods for more explanation.
  • Field Summary

    Fields inherited from class org.apache.calcite.rex.RexBuilder

    GET_OPERATOR, typeFactory
  • Constructor Summary

    Constructors
    Constructor
    Description
    FlinkRexBuilder(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.calcite.rex.RexNode
    makeFieldAccess(org.apache.calcite.rex.RexNode expr, int i)
    Compared to the original method we adjust the nullability of the nested column based on the nullability of the enclosing type.
    org.apache.calcite.rex.RexNode
    makeFieldAccess(org.apache.calcite.rex.RexNode expr, String fieldName, boolean caseSensitive)
    Compared to the original method we adjust the nullability of the nested column based on the nullability of the enclosing type.
    org.apache.calcite.rex.RexNode
    makeIn(org.apache.calcite.rex.RexNode arg, List<? extends org.apache.calcite.rex.RexNode> ranges)
    Convert the conditions into the IN and fix [CALCITE-4888]: Unexpected RexNode when call RelBuilder.in(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode...) to create an IN predicate with a list of varchar literals which have different length in RexBuilder.makeIn(org.apache.calcite.rex.RexNode, java.util.List<? extends org.apache.calcite.rex.RexNode>).
    org.apache.calcite.rex.RexLiteral
    makeZeroLiteral(org.apache.calcite.rel.type.RelDataType type)
    Creates a literal of the default value for the given type.

    Methods inherited from class org.apache.calcite.rex.RexBuilder

    addAggCall, addAggCall, addAggCall, baseUnit, constantNull, copy, decodeIntervalOrDecimal, deriveReturnType, encodeIntervalOrDecimal, ensureType, getOpTab, getTypeFactory, identityProjects, makeAbstractCast, makeApproxLiteral, makeApproxLiteral, makeBetween, makeBigintLiteral, makeBinaryLiteral, makeCall, makeCall, makeCall, makeCast, makeCast, makeCharLiteral, makeCorrel, makeDateLiteral, makeDateLiteral, makeDynamicParam, makeExactLiteral, makeExactLiteral, makeFlag, makeInputRef, makeInputRef, makeIntervalLiteral, makeIntervalLiteral, makeLiteral, makeLiteral, makeLiteral, makeLiteral, makeLiteral, makeLiteral, makeLocalRef, makeNewInvocation, makeNotNull, makeNullLiteral, makeNullLiteral, makeNullLiteral, makeOver, makeOver, makePatternFieldRef, makePreciseStringLiteral, makePreciseStringLiteral, makeRangeReference, makeRangeReference, makeReinterpretCast, makeSearchArgumentLiteral, makeTimeLiteral, makeTimeLiteral, makeTimestampLiteral, makeTimestampLiteral, makeTimestampWithLocalTimeZoneLiteral, makeTimeWithLocalTimeZoneLiteral, makeWindow, matchNullability, multiplyDivide

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FlinkRexBuilder

      public FlinkRexBuilder(org.apache.calcite.rel.type.RelDataTypeFactory typeFactory)
  • Method Details

    • makeFieldAccess

      public org.apache.calcite.rex.RexNode makeFieldAccess(org.apache.calcite.rex.RexNode expr, String fieldName, boolean caseSensitive)
      Compared to the original method we adjust the nullability of the nested column based on the nullability of the enclosing type.

      If the fields type is NOT NULL, but the enclosing ROW is nullable we still can produce nulls.

      Overrides:
      makeFieldAccess in class org.apache.calcite.rex.RexBuilder
    • makeFieldAccess

      public org.apache.calcite.rex.RexNode makeFieldAccess(org.apache.calcite.rex.RexNode expr, int i)
      Compared to the original method we adjust the nullability of the nested column based on the nullability of the enclosing type.

      If the fields type is NOT NULL, but the enclosing ROW is nullable we still can produce nulls.

      Overrides:
      makeFieldAccess in class org.apache.calcite.rex.RexBuilder
    • makeZeroLiteral

      public org.apache.calcite.rex.RexLiteral makeZeroLiteral(org.apache.calcite.rel.type.RelDataType type)
      Creates a literal of the default value for the given type.

      This value is:

      • 0 for numeric types;
      • FALSE for BOOLEAN;
      • The epoch for TIMESTAMP and DATE;
      • Midnight for TIME;
      • The empty string for string types (CHAR, BINARY, VARCHAR, VARBINARY).

      Uses '1970-01-01 00:00:00'(epoch 0 second) as zero value for TIMESTAMP_LTZ, the zero value '0000-00-00 00:00:00' in Calcite is an invalid time whose month and day is invalid, we workaround here. Stop overriding once CALCITE-4555 fixed.

      Overrides:
      makeZeroLiteral in class org.apache.calcite.rex.RexBuilder
      Parameters:
      type - Type
      Returns:
      Simple literal, or cast simple literal
    • makeIn

      public org.apache.calcite.rex.RexNode makeIn(org.apache.calcite.rex.RexNode arg, List<? extends org.apache.calcite.rex.RexNode> ranges)
      Convert the conditions into the IN and fix [CALCITE-4888]: Unexpected RexNode when call RelBuilder.in(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode...) to create an IN predicate with a list of varchar literals which have different length in RexBuilder.makeIn(org.apache.calcite.rex.RexNode, java.util.List<? extends org.apache.calcite.rex.RexNode>).

      The bug is because the origin implementation doesn't take FlinkTypeSystem.shouldConvertRaggedUnionTypesToVarying() into consideration. When this is true, the behaviour should not padding char. Please see https://issues.apache.org/jira/browse/CALCITE-4590 and https://issues.apache.org/jira/browse/CALCITE-2321. Please refer to org.apache.calcite.rex.RexSimplify.RexSargBuilder#getType for the correct behaviour.

      Once CALCITE-4888 is fixed, this method (and related methods) should be removed.

      Overrides:
      makeIn in class org.apache.calcite.rex.RexBuilder