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

ClassCastException converting SARG in RelNode to SQL

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      The stacktrace is the following:

      class org.apache.calcite.rex.RexLocalRef cannot be cast to class org.apache.calcite.rex.RexLiteral (org.apache.calcite.rex.RexLocalRef and org.apache.calcite.rex.RexLiteral are in unnamed module of loader 'app')
      java.lang.ClassCastException: class org.apache.calcite.rex.RexLocalRef cannot be cast to class org.apache.calcite.rex.RexLiteral (org.apache.calcite.rex.RexLocalRef and org.apache.calcite.rex.RexLiteral are in unnamed module of loader 'app')
      	at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:695)
      	at org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:597)
      ...
      

      The relevant expressions in the Calc operator are the following:

      ...expr#5=[Sarg[(10..11]]], expr#6=[SEARCH($t0, $t5)]...
      

      The current code in SqlImplementor considers the second argument to SEARCH is always a RexLiteral:

      ...
            case SEARCH:
              final RexCall search = (RexCall) rex;
              literal = (RexLiteral) search.operands.get(1);
              final Sarg sarg = castNonNull(literal.getValueAs(Sarg.class));
              //noinspection unchecked
              return toSql(program, search.operands.get(0), literal.getType(), sarg);
      ...
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jcamachorodriguez Jesus Camacho Rodriguez
            jcamachorodriguez Jesus Camacho Rodriguez
            Votes:
            0 Vote for this issue
            Watchers:
            3 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 - 50m
                50m

                Slack

                  Issue deployment