[Spark] Support TRUNCATE TABLE for DeltaTableV2#6747
Open
foss-contributor wants to merge 12 commits into
Open
Conversation
33c1cd0 to
19d0d56
Compare
openinx
reviewed
May 8, 2026
openinx
reviewed
May 8, 2026
openinx
reviewed
May 8, 2026
openinx
reviewed
May 8, 2026
openinx
reviewed
May 8, 2026
openinx
reviewed
May 8, 2026
19d0d56 to
fa8a086
Compare
8a65391 to
d150104
Compare
openinx
reviewed
May 11, 2026
openinx
reviewed
May 11, 2026
openinx
approved these changes
May 11, 2026
Collaborator
openinx
left a comment
There was a problem hiding this comment.
Generally looks good to me, pls address the remaining comments. I will merge it once all are ready. thanks @foss-contributor for the great work!
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.
Which Delta project/connector is this regarding?
Description
This PR adds
TRUNCATE TABLEsupport for Delta tables backed byDeltaTableV2.DeltaTableV2already advertises theTRUNCATEtable capability, but it did not implement Spark'sTruncatableTableinterface. This change wires truncate through the Delta transaction path so theoperation removes active files, records a
TRUNCATEoperation in Delta history, preserves rowtracking metadata tags, and keeps table metadata intact.
The PR also adds coverage for core Delta tables and Unity Catalog Delta tables:
DeltaTruncateTableSuitefor Spark/Delta truncate behavior.UCDeltaTableDDLTestas a UC DDL integration suite with truncate coverage for both externaland managed UC Delta tables.
How was this patch tested?
Added unit and integration tests covering
TRUNCATE TABLEcases:DESCRIBE DETAILfields, UC table id, and stableSHOW TBLPROPERTIESvalues unchanged while removing active files.Test commands run:
build/sbt 'spark/testOnly org.apache.spark.sql.delta.DeltaTruncateTableSuite org.apache.spark.sql.delta.DeltaTruncateTableWithCatalogOwnedBatch1Suite'build/sbt "spark/testOnly org.apache.spark.sql.delta.TruncateMetricsSuite"build/sbt sparkUnityCatalog/'testOnly io.sparkuctest.UCDeltaTableDDLTest'build/sbt 'spark/testOnly org.apache.spark.sql.delta.catalog.DeltaTableV2Suite'build/sbt 'spark/testOnly org.apache.spark.sql.delta.CustomCatalogSuite'build/sbt 'sparkUnityCatalog/test'Does this PR introduce any user-facing changes?
Yes.
Delta tables backed by
DeltaTableV2now support Spark SQLTRUNCATE TABLE. The operation removesall active data files through a Delta transaction while preserving table metadata.
Before change on spark-sql error:
After change: