ignite-3 icon indicating copy to clipboard operation
ignite-3 copied to clipboard

IGNITE-22164 Sql. Fixed conversion from SqlMerge AST to relational expression when columns defined in different order.

Open xtern opened this issue 1 year ago • 0 comments

https://issues.apache.org/jira/browse/IGNITE-22164

Issue description.

Schema with 2 tables.

TABLE TEST1(C1 INT, C2 INT)

TABLE TEST2(C1 INT, C2 INT)

SqlToRelConverter for the following insert statement

INSERT INTO TEST1 (C1, C2) SELECT C1, C2 FROM TEST2

produces the following rel node.

LogicalTableModify(table=[[PUBLIC, TEST1]], operation=[INSERT], flattened=[false])
  LogicalProject(C1=[$0], C2=[$1])
    LogicalTableScan(table=[[PUBLIC, TEST2]])

But if we swap columns C1 and C2.

INSERT INTO TEST1 (C2, C1) SELECT C2, C1 FROM TEST2

the result will be

LogicalTableModify(table=[[PUBLIC, TEST1]], operation=[INSERT], flattened=[false])
  LogicalTableScan(table=[[PUBLIC, TEST2]])

convertMerge() expects projection in the input of table modify node and fails with the following

Caused by: java.lang.ClassCastException: class org.apache.ignite.internal.sql.engine.rel.logical.IgniteLogicalTableScan cannot be cast to class org.apache.calcite.rel.logical.LogicalProject

Calcite issue: https://issues.apache.org/jira/browse/CALCITE-6412

As a naive workaround, an additional assembly of column expressions has been added to convertMerge() :thinking:

xtern avatar May 20 '24 19:05 xtern