Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-16799

SQL Calcite: ArrayIndexOutOfBoundsException when serializing MINUS_DATE operation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.13
    • sql

    Description

      If you run the following test:

       

      // ProjectFilterScanMergePlannerTest.java
      
      @Test
      public void testProjectWithDateMinusExprMerge() throws Exception {
          assertPlan("SELECT (DATE '2021-03-01' - DATE '2021-01-01') months FROM tbl WHERE c = 0", publicSchema, isInstanceOf(IgniteTableScan.class)
              .and(scan -> scan.projects() != null)
              .and(scan -> scan.condition() != null)
              .and(scan -> ImmutableBitSet.of(2).equals(scan.requiredColumns()))
          );
      } 

      , you will get the following exception:

      java.lang.ArrayIndexOutOfBoundsException: 2
      	at com.google.common.collect.RegularImmutableList.get(RegularImmutableList.java:60)
      	at org.apache.calcite.rex.RexCallBinding.getOperandType(RexCallBinding.java:149)
      	at org.apache.calcite.sql.type.OrdinalReturnTypeInference.inferReturnType(OrdinalReturnTypeInference.java:40)
      	at org.apache.calcite.sql.type.SqlTypeTransformCascade.inferReturnType(SqlTypeTransformCascade.java:58)
      	at org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:537)
      	at org.apache.calcite.rex.RexBuilder.deriveReturnType(RexBuilder.java:290)
      	at org.apache.ignite.internal.processors.query.calcite.externalize.RelJson.toRex(RelJson.java:472)
      	at org.apache.ignite.internal.processors.query.calcite.externalize.RelJsonReader$RelInputImpl.getExpressionList(RelJsonReader.java:248)
      

       

      This caused by definition of the MINUS_DATE operation:

      public SqlDatetimeSubtractionOperator() {
        super(
            "-",
            SqlKind.MINUS,
            40,
            true,
            ReturnTypes.ARG2_NULLABLE,
            InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
      } 

      The return type should be inferred from the 3rd argument, but it appears after converting AST -> REX, the resulting expression has 2 arguments only.

      This seems to be a bug in Calcite Framework, but we could avoid this problem by serializing the operation type for each operation. 

       

       

       

      Attachments

        Issue Links

          Activity

            People

              alex_pl Aleksey Plekhanov
              korlov Konstantin Orlov
              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 - 20m
                  20m