[
https://issues.apache.org/jira/browse/CALCITE-7276?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18036189#comment-18036189
]
Dmitry Sysolyatin edited comment on CALCITE-7276 at 11/7/25 9:53 AM:
---------------------------------------------------------------------
[~bestbeforetoday] I’ve fixed the issue [1]. Could you please contribute TPC-DS
test cases from your project (Feel free to add them in the same PR [1]) ? That
would help prevent similar bugs in the future
[1] https://github.com/apache/calcite/pull/4623
was (Author: dmsysolyatin):
[~bestbeforetoday] I’ve fixed the issue [1]. Could you please contribute TPC-DS
test cases from your project (Feel free to add them in the PR [1]) ? That would
help prevent similar bugs in the future
[1] https://github.com/apache/calcite/pull/4623
> SqlToRelConverter throws exception for UPDATE if identifier expansion disabled
> ------------------------------------------------------------------------------
>
> Key: CALCITE-7276
> URL: https://issues.apache.org/jira/browse/CALCITE-7276
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.41.0
> Reporter: Mark S. Lewis
> Priority: Major
> Labels: pull-request-available
>
> I am seeing a regression in Calcite 1.41.0 on a SQL UPDATE call that worked
> in Calcite 1.40.0. For example, using the TPC-DS schema, the following query:
>
> {code:java}
> UPDATE customer SET c_first_name = 'Alice' WHERE c_customer_sk =
> 'some_key'{code}
>
> fails with:
>
> {quote}java.lang.AssertionError: Unexpected select list size. Select list
> should contain both target table columns and set expressions
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertUpdate(SqlToRelConverter.java:4472)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3997)
> at
> org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:631)
> {quote}
>
> It is failing on this check, introduced in commit
> 95350ed1a449bbb2f008fcf2b704544e7d95c410:
>
> [https://github.com/apache/calcite/blob/42ff295d6e28672a2ad81b1c30abfbdf44544212/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L4469-L4475]
>
> {code:java}
> // `sourceSelect` should contain target columns values plus source expressions
> if (sourceSelect.getSelectList().size()
> != targetTable.getRowType().getFieldCount() +
> call.getSourceExpressionList().size()) {
> throw new AssertionError(
> "Unexpected select list size. Select list should contain both target
> table columns and "
> + "set expressions");
> }{code}
>
> If I take the current state of the Calcite main branch (which also exhibits
> the same failure) and revert commit 95350ed1a449bbb2f008fcf2b704544e7d95c410,
> the resulting code allows the SQL UPDATE above to run successfully.
>
> Looking in the debugger at the failing case, the SqlNode passed into
> SqlRelConverter.convertQuery() (with needsValidation=true, top=true) contains:
>
> {noformat}
> UPDATE `CUSTOMER` SET `C_FIRST_NAME` = 'Alice'
> WHERE `C_CUSTOMER_SK` = 'some_key'{noformat}
>
> The sourceSelect for the SqlNode is null. Once execution passes the line:
>
> {code:java}
> query = validator().validate(query);{code}
>
> The SqlNode (query) has a sourceSelect of:
>
> {noformat}
> SELECT *, CAST('Alice' AS CHAR(16) CHARACTER SET `ISO-8859-1`) AS `EXPR$0`
> FROM `CUSTOMER`
> WHERE `CUSTOMER`.`C_CUSTOMER_SK` = CAST('some_key' AS BIGINT){noformat}
>
> This means that its _selectList_ has size 2. When it reaches the check linked
> above, this size is expected to equal the sum of the _targetTable rowType
> fieldCount_ (18) and _call sourceExpressionList_ size (1). 2 != 19 so the
> assertion fails.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)