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

Datetime MINUS throws ArrayIndexOutOfBounds error when serializing toRex

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.37.0
    • None

    Description

      We found a bug in RelJson#toRex for the TIMESTAMP_DIFF call for Big Query dialect.

      TIMESTAMP_DIFF is translated to the MINUS_DATE operator with a return type explicitly declared as the interval.

      MINUS_DATE uses an ARG2_NULLABLE return type inference which requires 3 operands. This is fine in most cases where the RexCall is then used to generate SQL or for native implementations.

      However, in RelJson#toRex, when it tries to reconstruct the entire call to a RexNode, it attempts to derive the return type of the MINUS_DATE operator using the ARG2_NULLABLE inference. This throws an error as there are only 2 operands given to the MINUS_DATE operator.

       

      The solution here is to do something similar to how we handle CAST and to add in "type" when serializing to JSON in RelJson.toJson(RexNode node) for SqlKind.MINUS so that jsonType will be defined in toRex.

       

      Attachments

        Activity

          People

            oliverlee Oliver Lee
            oliverlee Oliver Lee
            Votes:
            0 Vote for this issue
            Watchers:
            4 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 - 1h 10m
                1h 10m