You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "korlov42 (via GitHub)" <gi...@apache.org> on 2024/08/02 13:27:48 UTC
Re: [PR] IGNITE-18883: Bug. Potentially incorrect definition of rows to insert for MERGE [ignite-3]
korlov42 commented on code in PR #4155:
URL: https://github.com/apache/ignite-3/pull/4155#discussion_r1701849664
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/rel/ModifyNode.java:
##########
@@ -361,10 +361,20 @@ private static int[] applyOffset(int[] srcMapping, int offset) {
rowsToUpdate = new ArrayList<>();
for (RowT row : rows) {
- // this check doesn't seem correct because NULL could be a legit value for column,
- // but this is how it was implemented before, so I just file an issue to deal with this later
- // TODO: https://issues.apache.org/jira/browse/IGNITE-18883
- if (handler.get(updateColumnOffset, row) == null) {
+ // Merge operation uses a left join as its input, so in order to distinguish between new rows and modified rows
+ // (rows produced by WHEN MATCHED, and rows produces by WHEN NOT MATCHED clauses)
+ // we need to check all columns of a destination table for null values.
+ //
+ // Since every table has a primary key and all primary keys columns are not nullable, we can assume that
+ // a row is produced by the WHEN NOT MATCHED clause iff every column in the subset of input columns
+ // that belongs to the destination table has a NULL value. Otherwise it belongs to the WHEN MATCH clause.
+
+ boolean insertRow = true;
+ for (int i = updateColumnOffset; i < updateColumnOffset + mapping.length; i++) {
+ insertRow = insertRow && handler.get(i, row) == null;
Review Comment:
```suggestion
if (!handler.isNull(i, row)) {
insertRow = false;
break;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org