Skip to content

Commit abbd869

Browse files
committed
Fix channel mapping in createColumnValueAndRowIdChannels
Previously, createColumnValueAndRowIdChannels() iterated over all variableReferenceExpressions and attempted to locate them in columnValueAndRowIdSymbols, relying on the output order and performing an incorrect size check. This commit fixes the logic by iterating directly over columnValueAndRowIdSymbols and verifying each one’s position in variableReferenceExpressions. This removes the incorrect ordering assumption and ensures accurate channel mapping when multiple identical values or updates are involved.
1 parent bd66d87 commit abbd869

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedTestBase.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,18 @@ public void testInformationSchemaQueries()
24392439
assertQuerySucceeds("DROP SCHEMA ICEBERG.TEST_SCHEMA2");
24402440
}
24412441

2442+
@Test
2443+
public void testUpdateWithDuplicateValues()
2444+
{
2445+
String tableName = "test_update_duplicate_values_" + randomTableSuffix();
2446+
assertUpdate("CREATE TABLE " + tableName + "(id int, column1 varchar(10), column2 varchar(10), column3 int)");
2447+
assertUpdate("INSERT INTO " + tableName + " VALUES (1, 'a', 'a', 1), (2, 'b', 'b', 1), (3, 'c', 'c', 1)", 3);
2448+
2449+
// update single row with duplicate values
2450+
assertUpdate("UPDATE " + tableName + " SET column1 = CAST(1 as varchar), column2 = CAST(1 as varchar), column3 = 11 WHERE id = 1", 1);
2451+
assertQuery("SELECT id, column1, column2, column3 FROM " + tableName, "VALUES (1, '1', '1', 11), (2, 'b', 'b', 1), (3, 'c', 'c', 1)");
2452+
}
2453+
24422454
@Test
24432455
public void testUpdateWithPredicates()
24442456
{

presto-main-base/src/main/java/com/facebook/presto/sql/planner/LocalExecutionPlanner.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,16 +3008,15 @@ private List<Integer> createColumnValueAndRowIdChannels(List<VariableReferenceEx
30083008
{
30093009
Integer[] columnValueAndRowIdChannels = new Integer[columnValueAndRowIdSymbols.size()];
30103010
int symbolCounter = 0;
3011-
// This depends on the outputSymbols being ordered as the blocks of the
3012-
// resulting page are ordered.
3013-
for (VariableReferenceExpression variableReferenceExpression : variableReferenceExpressions) {
3014-
int index = columnValueAndRowIdSymbols.indexOf(variableReferenceExpression);
3015-
if (index >= 0) {
3016-
columnValueAndRowIdChannels[index] = symbolCounter;
3017-
}
3011+
for (VariableReferenceExpression columnValueAndRowIdSymbol : columnValueAndRowIdSymbols) {
3012+
int index = variableReferenceExpressions.indexOf(columnValueAndRowIdSymbol);
3013+
3014+
verify(index >= 0, "Could not find columnValueAndRowIdSymbol %s in the variableReferenceExpressions %s", columnValueAndRowIdSymbol, variableReferenceExpressions);
3015+
columnValueAndRowIdChannels[symbolCounter] = index;
3016+
30183017
symbolCounter++;
30193018
}
3020-
checkArgument(symbolCounter == columnValueAndRowIdSymbols.size(), "symbolCounter %s should be columnValueAndRowIdChannels.size() %s", symbolCounter);
3019+
30213020
return Arrays.asList(columnValueAndRowIdChannels);
30223021
}
30233022

0 commit comments

Comments
 (0)