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
- is part of
-
IGNITE-12248 Apache Calcite based query execution engine
- Open
- links to