Repository navigation
[datafusion] Support SQL DELETE on deduplicate primary-key tables - #1392
Open
SteNicholas wants to merge 1 commit into
Open
SteNicholas wants to merge 1 commit into
SteNicholas wants to merge 1 commit into
Conversation
DataFusion SQL rejected DELETE on every primary-key table, although the primary-key writer already accepts DELETE records, so rows could only be removed through other engines. - Route DELETE on primary-key tables to execute_primary_key_delete, which scans the logical rows matching the WHERE clause, marks them with a DELETE _VALUE_KIND column and writes them through TableWrite, so the tombstones keep the primary-key, partition and sequence-field values. Commit them through the existing commit path and return the matched-row count; a delete without matches publishes no snapshot. - Plan the scan against one captured snapshot: the FROM source must be the target table itself, not a view or a time-traveled copy, and self-references in the predicate, including subqueries, read the same snapshot. Concurrent upserts follow the normal primary-key merge rules, including sequence.field ordering. - Write all tombstones before committing, so commit retries reuse the prepared files instead of rescanning. Close the writer when the scan or write fails to discard unprepared output; when the commit fails, keep the prepared files and report the table and commit user, since the snapshot may have been published. - Reject other merge engines, ignore-delete including its fallback keys, rowkind.field, query-auth and DELETE clauses beyond a single target with WHERE before scanning or writing. - Add unit tests for snapshot pinning, replaced targets, commit retries and failure cleanup, and integration tests for predicates, NULLs, subqueries, partitions, composite keys, dynamic buckets, sequence fields, concurrent upserts and rejections, replacing the old rejection tests. - Document the supported tables, snapshot, concurrency and retry semantics and the unsupported options in the SQL reference.
Member
Author
|
Ping @JingsongLi. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Linked issue: close #1379
DataFusion SQL rejected DELETE on every primary-key table, although the primary-key writer already accepts DELETE records. This adds SQL DELETE for primary-key tables using
merge-engine=deduplicate, following Spark'sDeleteFromPaimonTableCommand#performPrimaryKeyDelete.Brief change log
execute_primary_key_delete, which scans the logical rows matching theWHEREclause, marks them with a DELETE_VALUE_KINDcolumn and writes them throughTableWrite, so the tombstones keep the primary-key, partition and sequence-field values. Commit them through the existing commit path and return the matched-row count; a delete without matches publishes no snapshot.FROMsource must be the target table itself, not a view or a time-traveled copy, and self-references in the predicate, including subqueries, read the same snapshot. Concurrent upserts follow the normal primary-key merge rules, includingsequence.fieldordering.ignore-deleteincluding its fallback keys,rowkind.field,query-authand DELETE clauses beyond a single target withWHEREbefore scanning or writing.Tests
crates/integrations/datafusion/src/delete/tests.rs: snapshot pinning of the target and predicate self-references, replaced targets, commit retries without rescanning, uncertain commits, tombstone write failure cleanup and rejection of unsupported options before scanning.crates/integrations/datafusion/tests/pk_delete_tests.rs: predicates, NULLs, no-match and never-written tables, subqueries, partitions, composite keys, dynamic buckets, quoted names, sequence fields and sort orders, concurrent upserts, scan failure cleanup, existing target guards and rejected merge engines, options and syntax.test_delete_rejects_primary_key_tableandtest_pk_aggregation_rejects_delete.API and Format
No API or storage format change.
Documentation
Update
docs/src/sql.mdwith the supported primary-key tables, snapshot, concurrency and retry semantics, and the unsupported options.🤖 Generated with Claude Code