[
https://issues.apache.org/jira/browse/CALCITE-7276?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18036214#comment-18036214
]
Mark S. Lewis commented on CALCITE-7276:
----------------------------------------
[~dmsysolyatin] I already contributed my TPC-DS tests in
[org.apache.calcite.sql2rel.TpcdsSqlToRelTest|https://github.com/apache/calcite/blob/main/plus/src/test/java/org/apache/calcite/sql2rel/TpcdsSqlToRelTest.java].
I just used TPC-DS for my reproduce since the schema (and tests) were already
there for me to easily demonstrate the problem. The actual local test that hit
this issue involves more than just Calcite, but the SQL converted to Calcite
rel is very simple:
{code:sql}
update src1 set intcol=10 where charcol='a'
{code}
using a table defined as:
{code:sql}
create table src1 (intcol int, charcol varchar(10));
create table src2 (intcol int, charcol varchar(10));
{code}
Is there value in adding that in addition to the unit test you already created?
> 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)