Konstantin Orlov created IGNITE-16799:
-----------------------------------------
Summary: SQL Calcite: ArrayIndexOutOfBoundsException when
serializing MINUS_DATE operation
Key: IGNITE-16799
URL: https://issues.apache.org/jira/browse/IGNITE-16799
Project: Ignite
Issue Type: Bug
Components: sql
Reporter: Konstantin Orlov
If you run the following test:
{code:java}
// 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()))
);
} {code}
, you will get the following exception:
{noformat}
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)
{noformat}
This caused by definition of the MINUS_DATE operation:
{code:java}
public SqlDatetimeSubtractionOperator() {
super(
"-",
SqlKind.MINUS,
40,
true,
ReturnTypes.ARG2_NULLABLE,
InferTypes.FIRST_KNOWN, OperandTypes.MINUS_DATE_OPERATOR);
} {code}
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.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)