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

"vFloat in (1.0, 2.0)" throws UnsupportedOperationException

    XMLWordPrintableJSON

    Details

      Description

      Check this test in RexBuilderTest:

      @Test void testMakeIn() {
          final RelDataTypeFactory typeFactory =
                  new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
          final RexBuilder rexBuilder = new RexBuilder(typeFactory);
          final RelDataType floatType = typeFactory.createSqlType(SqlTypeName.FLOAT);
          RexNode left = rexBuilder.makeInputRef(floatType, 0);
          final RexNode literal1 = rexBuilder.makeLiteral(1.0f, floatType);
          final RexNode literal2 = rexBuilder.makeLiteral(2.0f, floatType);
          RexNode inCall = rexBuilder.makeIn(left, ImmutableList.of(literal1, literal2));
          assertThat(inCall.getKind(), is(SqlKind.SEARCH));
        }
      

      The stacktrace is:

      class org.apache.calcite.sql.type.SqlTypeName: FLOAT
      java.lang.UnsupportedOperationException: class org.apache.calcite.sql.type.SqlTypeName: FLOAT
      	at org.apache.calcite.util.Util.needToImplement(Util.java:1085)
      	at org.apache.calcite.rex.RexLiteral.appendAsJava(RexLiteral.java:726)
      	at org.apache.calcite.rex.RexLiteral.toJavaString(RexLiteral.java:427)
      	at org.apache.calcite.rex.RexLiteral.computeDigest(RexLiteral.java:289)
      	at org.apache.calcite.rex.RexLiteral.<init>(RexLiteral.java:233)
      	at org.apache.calcite.rex.RexLiteral.toLiteral(RexLiteral.java:762)
      	at org.apache.calcite.rex.RexLiteral.lambda$printSarg$4(RexLiteral.java:733)
      	at org.apache.calcite.util.RangeSets$Printer.singleton(RangeSets.java:409)
      	at org.apache.calcite.util.RangeSets.forEach(RangeSets.java:249)
      	at org.apache.calcite.util.Sarg.lambda$printTo$0(Sarg.java:119)
      	at org.apache.calcite.linq4j.Ord.forEach(Ord.java:157)
      	at org.apache.calcite.util.Sarg.printTo(Sarg.java:115)
      	at org.apache.calcite.rex.RexLiteral.printSarg(RexLiteral.java:732)
      	at org.apache.calcite.rex.RexLiteral.lambda$appendAsJava$1(RexLiteral.java:673)
      	at org.apache.calcite.util.Util.asStringBuilder(Util.java:2525)
      	at org.apache.calcite.rex.RexLiteral.appendAsJava(RexLiteral.java:672)
      	at org.apache.calcite.rex.RexLiteral.toJavaString(RexLiteral.java:427)
      	at org.apache.calcite.rex.RexLiteral.computeDigest(RexLiteral.java:289)
      	at org.apache.calcite.rex.RexLiteral.<init>(RexLiteral.java:233)
      	at org.apache.calcite.rex.RexBuilder.makeLiteral(RexBuilder.java:990)
      	at org.apache.calcite.rex.RexBuilder.makeSearchArgumentLiteral(RexBuilder.java:1085)
      	at org.apache.calcite.rex.RexBuilder.makeIn(RexBuilder.java:1335)
      	at org.apache.calcite.rex.RexBuilderTest.testMakeIn(RexBuilderTest.java:621)
      

      The root cause is that RexLiteral#strictTypeName has different type name strategies with what RexBuilder.makeLiteral follows, the best way to fix is to make the rules synced, but here i only give a simple fix because the code path only used for Sarg digest.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                danny0405 Danny Chen
                Reporter:
                danny0405 Danny Chen
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m