[
https://issues.apache.org/jira/browse/CALCITE-7220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dmitry Sysolyatin updated CALCITE-7220:
---------------------------------------
Description:
The following test
{code:java}
@Test void testUpdate() {
final String sql0 =
"update \"foodmart\".\"product\" set \"product_name\" =
\"product_name\" || '_'"
+ "where \"product_id\" > 10";
final String expected0 = "";
sql(sql0).ok(expected0);
}
{code}
throws an exception:
{code:java}
field ordinal 3 out of range {}
java.lang.AssertionError: field ordinal 3 out of range {}
at
org.apache.calcite.rel.rel2sql.SqlImplementor$AliasContext.field(SqlImplementor.java:1702)
{code}
This happens because the current code uses an empty context for exprList. But
looks like using exprList is not needed at all.
was:
The following test
{code:java}
@Test void testUpdate() {
final String sql0 =
"update \"foodmart\".\"product\" set \"product_name\" =
\"product_name\" || '_'"
+ "where \"product_id\" > 10";
final String expected0 = "";
sql(sql0).ok(expected0);
}
{code}
throws an exception:
{code:java}
field ordinal 3 out of range {}
java.lang.AssertionError: field ordinal 3 out of range {}
at
org.apache.calcite.rel.rel2sql.SqlImplementor$AliasContext.field(SqlImplementor.java:1702)
{code}
This happens because the current code uses an empty context for exprList. But
looks like using exprList is not needed at all.
I see the following solution:
# During validation, {{ValidatorImpl.createSourceSelectForUpdate}} rewrites
sourceSelect into:
{code:java}
SELECT *, <call.getSourceExpressionList()> FROM .... WHERE ....
{code}
# When the UPDATE SqlNode is converted into a RelNode, TableModify.input is
the RelNode for that SELECT above.
# In {{RelToSqlConverter.visit(TableModify)}}, we call
visitInput(TableModify), which produces a SqlSelect that already contains
correct source expressions. So, instead of converting
{{exprList(TableModify.getSourceExpressionList())}}, we should directly use the
SqlNodes produced from TableModify.input.
> RelToSqlConverter throws exception for UPDATE with self-referencing column in
> SET
> ---------------------------------------------------------------------------------
>
> Key: CALCITE-7220
> URL: https://issues.apache.org/jira/browse/CALCITE-7220
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.40.0
> Reporter: Dmitry Sysolyatin
> Assignee: Dmitry Sysolyatin
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.41.0
>
>
> The following test
> {code:java}
> @Test void testUpdate() {
> final String sql0 =
> "update \"foodmart\".\"product\" set \"product_name\" =
> \"product_name\" || '_'"
> + "where \"product_id\" > 10";
> final String expected0 = "";
> sql(sql0).ok(expected0);
> }
> {code}
> throws an exception:
> {code:java}
> field ordinal 3 out of range {}
> java.lang.AssertionError: field ordinal 3 out of range {}
> at
> org.apache.calcite.rel.rel2sql.SqlImplementor$AliasContext.field(SqlImplementor.java:1702)
> {code}
> This happens because the current code uses an empty context for exprList. But
> looks like using exprList is not needed at all.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)