Skip to content

HIVE-29815: Iceberg: [V3] Support ROW LINEAGE in Copy-On-Write DELETE operations - #6698

Open
Aggarwal-Raghav wants to merge 2 commits into
apache:masterfrom
Aggarwal-Raghav:HIVE-29815
Open

HIVE-29815: Iceberg: [V3] Support ROW LINEAGE in Copy-On-Write DELETE operations#6698
Aggarwal-Raghav wants to merge 2 commits into
apache:masterfrom
Aggarwal-Raghav:HIVE-29815

Conversation

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Check HIVE-29815
This PR updates CopyOnWriteDeleteRewriter.java to explicitly select and preserve ROW__LINEAGE__ID and LAST__UPDATED__SEQUENCE__NUMBER when rewriting files during a Copy-On-Write DELETE operation on Iceberg V3 tables.

Why are the changes needed?

Currently, when a user deletes a row in COW mode, the surviving rows are rewritten into a new file without their original lineage metadata. As a result, they get assigned brand new lineage IDs and sequence numbers

Does this PR introduce any user-facing change?

Yes

How was this patch tested?

With q file and on spark engine as well

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

spark Output:
Screenshot 2026-08-14 at 1 23 56 AM

Hive Before Fix:
Screenshot 2026-08-14 at 12 53 24 AM

@ayushtkn ayushtkn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanx @Aggarwal-Raghav for the fix, minor request around the test.

Comment on lines +86 to +88
)
STORED BY iceberg
TBLPROPERTIES ('format-version'='3', 'write.delete.mode'='copy-on-write');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u add a test around a partitioned table as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ayushtkn ayushtkn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the build comes clean, changes LGTM

@kokila-19

Copy link
Copy Markdown
Contributor

Good Catch @Aggarwal-Raghav
LGTM +1

@sonarqubecloud

Copy link
Copy Markdown

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

I've found 1 more potential bug/scope of improvement. Please hold on merging it.

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

The new issue i found was for row lineage for MERGE WHEN DELETE query.

MERGE INTO ice_cow_merge_delete_only t
USING merge_source s
ON t.id = s.id
WHEN MATCHED THEN DELETE;

The following code doesn't check for merge when delete. it only checks for hasWhenMatchedUpdateClause

public static boolean shouldAddRowLineageColumnsForMerge(MergeStatement mergeStatement, Configuration conf) {
boolean shouldAddRowLineageColumns =
supportsRowLineage(mergeStatement.getTargetTable()) && mergeStatement.hasWhenMatchedUpdateClause();
setRowLineage(conf, shouldAddRowLineageColumns);
return shouldAddRowLineageColumns;
}

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

@ayushtkn
There is 1 more bug in hive. Merge when delete is adding additonal row instead of deleteing it. I'm filing a new JIRA for it

SPARK:
Screenshot 2026-08-14 at 4 49 48 PM

HIVE:
Screenshot 2026-08-14 at 5 12 10 PM

@Aggarwal-Raghav

Copy link
Copy Markdown
Contributor Author

Filed HIVE-29816. You can proceed with this PR merge as per your convenience

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants