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

Search/sarg simplification leaves is not null(literal) unsimplified

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.34.0
    • 1.35.0
    • core
    • None

    Description

      Case: SEARCH(100500, Sarg[=]) (Sarg[=] is "all values match, unknown as unknown").

      While the issue does not look severe, it results in rex fuzzer false positives, so it might mask true bugs.

      Expected: true
      Actual:

      unknown as unknown: OR(IS NOT NULL(0), null)
      unknown as false: IS NOT NULL(0)
      unknown as true: true <-- finally got the right answer
      

      Test:

          checkSimplify(
                      rexBuilder.makeCall(
                          SqlStdOperatorTable.SEARCH,
                          literal(BigDecimal.ZERO),
                          rexBuilder.makeSearchArgumentLiteral(
                              Sarg.of(RexUnknownAs.UNKNOWN, ImmutableRangeSet.of(Range.<BigDecimal>all())),
                              tInt())),
              "true"
          );
      

      fuzzer:

        @Test void singleFuzzyTest() {
          Random r = new Random();
          r.setSeed(-8889103384303613092L);
          RexFuzzer fuzzer = new RexFuzzer(rexBuilder, typeFactory);
          generateRexAndCheckTrueFalse(fuzzer, r);
        }
      AssertionFailedError: SEARCH(100500, Sarg[=])
      rexBuilder.makeCall(SqlStdOperatorTable.SEARCH, literal(100500), literal(Sarg[=])) isAlwaysTrue, so it should simplify to TRUE unknownAsFalse ==> expected: <true> but was: <IS NOT NULL(100500)>
      	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)
      	at org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:69)
      	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:188)
      	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1146)
      	at org.apache.calcite.test.fuzzer.RexProgramFuzzyTest.checkUnknownAs(RexProgramFuzzyTest.java:251)
      	at org.apache.calcite.test.fuzzer.RexProgramFuzzyTest.checkUnknownAsAndShrink(RexProgramFuzzyTest.java:202)
      	at org.apache.calcite.test.fuzzer.RexProgramFuzzyTest.checkUnknownAs(RexProgramFuzzyTest.java:165)
      	at org.apache.calcite.test.fuzzer.RexProgramFuzzyTest.generateRexAndCheckTrueFalse(RexProgramFuzzyTest.java:454)
      	at org.apache.calcite.test.fuzzer.RexProgramFuzzyTest.singleFuzzyTest(RexProgramFuzzyTest.java:463)
      

      Attachments

        Issue Links

          Activity

            People

              Runking Runkang He
              vladimirsitnikov Vladimir Sitnikov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: