Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-2069

RexSimplify.removeNullabilityCast() always removes cast for operand with ANY type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.15.0
    • None
    • None

    Description

      When a field is received from Dynamic Table, its type left ANY, and it is used in the filter condition with the cast, which actually should produce physical cast (for example we are trying to cast varchar to boolean) RexSimplify.removeNullabilityCast() removes this cast and lefts only field in condition.
      This test helps to observe this issue:

        @Test public void testFilterCastAny() {
          final RelBuilder builder = RelBuilder.create(config().build());
          final RelDataType intType = builder.getTypeFactory().createSqlType(SqlTypeName.ANY);
          RelNode root =
              builder.scan("EMP")
                  .filter(
                      builder.cast(
                          builder.patternField("varchar_field", intType, 0),
                          SqlTypeName.BOOLEAN))
                  .build();
          assertThat(str(root),
              is("LogicalFilter(condition=[CAST(varchar_field.$0):BOOLEAN NOT NULL])\n"
                  + "  LogicalTableScan(table=[[scott, EMP]])\n"));
        }
      

      It happens because SqlTypeUtil.equalSansNullability() returns true if any of its arguments has ANY type.

      Attachments

        Activity

          People

            julianhyde Julian Hyde
            volodymyr Vova Vysotskyi
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: