[ 
https://issues.apache.org/jira/browse/CALCITE-7220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18029158#comment-18029158
 ] 

Dmitry Sysolyatin commented on CALCITE-7220:
--------------------------------------------

[~mbudiu] [~rubenql] I removed fix version 1.41

The reason is that while the original bug was fixed, the fix now allows 
incorrect behavior. There’s a bug in `SqlToRelConverter` when generating the 
`LogicalPlan` for an `UPDATE`. This issue existed before as well, but 
previously it caused an exception inside `RelToSqlConverter`. Example:
{code}
 final String sql1 = "update \"foodmart\".\"product\"\n"
        + "set \"product_name\" = ("
        + "  SELECT \"product_name\" FROM \"foodmart\".\"product\" p "
        + "  WHERE p.\"product_id\" = \"product\".\"product_id\" "
        + "  LIMIT 1"
        + ")";
    final String expected1 = ""; <--     // at the moment it produces UPDATE 
\"foodmart\".\"product\" SET \"product_name\" = \"product_class_id\"
    sql(sql1).ok(expected1);
{code}

When before it was exception in this case: `field ordinal 0 out of range {}`.

Since this is a modification operation, it’s better to throw an exception than 
to run an incorrect UPDATE that might set the wrong value.
I’ll try to allocate time and fix it next week, but please go ahead and release 
Calcite without waiting for this task

> 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
>
> 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)

Reply via email to