[
https://issues.apache.org/jira/browse/CALCITE-7220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18028429#comment-18028429
]
Ruben Q L commented on CALCITE-7220:
------------------------------------
[~dmsysolyatin] I assume this is not regression that "appeared" on 1.40, but
rather an old issue that was recently discovered right?
If that's the case, considering we're approaching 1.41 deadline, we may need to
push this back into a later version if we don't have a quick fix for it.
> 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
> 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.
> 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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)