Repository navigation
Conversation
sezruby
force-pushed
the
feat/delta-native-constraints
branch
from
November 26, 2026 18:03
c8fcf18 to
d5ac107
Compare
…onverting rows A native Delta write checked its constraints on Velox batches only when every constraint was a top-level NOT NULL. Any other constraint made the whole write fall back to Delta's row-based DeltaInvariantCheckerExec, which converts every row of every column from columnar to row and back. Such constraints include a CHECK constraint, a legacy column invariant, the CHECK that Delta adds for replaceWhere or when a write provides a generated column, and a NOT NULL field of a struct. GlutenDeltaReferencedColumnsChecker now checks these constraints with Delta's own CheckDeltaInvariant expressions, built and time-resolved as DeltaInvariantCheckerExec builds them. It exports only the columns the checks reference from each Velox batch to Arrow, and evaluates the checks on those rows, so a violation raises the same error as Delta. When a CHECK prints a struct, array or map value in its message, the checks run on unsafe copies of the rows, as in Delta, so that the value prints the same. When a write has constraints, Delta also puts a ProjectExec of Empty2Null on its string partition columns (TransactionalWrite.convertEmptyToNullIfNeeded). Delta adds it after Gluten's rules have run, so it stays row-based and converted every row as well. GlutenDeltaEmpty2Null runs that projection in a ProjectExecTransformer, since Velox runs Empty2Null, and keeps Delta's ProjectExec when the transformer does not validate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sezruby
force-pushed
the
feat/delta-native-constraints
branch
from
November 27, 2026 02:54
d5ac107 to
b988d72
Compare
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.
What changes are proposed in this pull request?
Part of apache#10215 ("Constraint expression needs to offload"). apache#12647 keeps top-level NOT NULL checks native; this PR does the same for every other constraint.
A native Delta write checks its constraints on Velox batches only when every constraint is a top-level NOT NULL. Any other constraint makes the whole write fall back to Delta's row-based
DeltaInvariantCheckerExec, which converts every row of every column from columnar to row and back. Delta has two kinds of constraints, NOT NULL and CHECK. CHECK constraints, legacy column invariants (delta.invariants), the CHECK Delta adds forreplaceWhere, and the CHECK it adds when a write provides a generated column are all CHECKs. NOT NULL fields of a struct fall back too.Changes
GlutenDeltaReferencedColumnsCheckerchecks these constraints with Delta's ownCheckDeltaInvariantexpressions, built and time-resolved asDeltaInvariantCheckerExecbuilds them. It exports only the columns the checks reference from each Velox batch to Arrow and evaluates the checks on those rows, so a violation raises the same error as Delta. When a CHECK prints a struct, array or map value in its message, the checks run on unsafe copies of the rows, as in Delta, so the value prints the same.GlutenDeltaEmpty2Null: when a write has constraints, Delta puts aProjectExecofEmpty2Nullon the string partition columns (TransactionalWrite.convertEmptyToNullIfNeeded). Delta adds it after Gluten's rules have run, so it stays row-based and converts every row too. It now runs in aProjectExecTransformer; Delta'sProjectExecis kept when the transformer does not validate.src-delta33binds the checks withwithBoundReferences(extractors are a map there);src-delta4usesBindReferences.VeloxDelta.md: the CHECK / NOT NULL row.A violation is Delta's own exception. With apache#13561, it keeps its type when native code pulls the checked batches, such as the writer's sort on a partitioned write or an optimized write's shuffle, so this change needs no handling of its own for that.
Coverage. Each case ran natively on Spark 3.5.5 / Delta 3.3.2 (Linux x86-64), with native write on and the native libraries of a 2026-11-27 nightly bundle (which includes apache#13561), with and without this change. "Checker" is the checker in the Velox writer's plan.
save(path)appendsave(path)appendcurrent_date(), array, map, struct field, boolean, binary, doublesave(path)append, partitionedsave(path)overwrite,replaceWherereplaceWherepredicateIn every case, a violating write raises the same exception and message as with native write off, with and without this change. SQL
INSERT, MERGE and streaming writes are written by Delta's writer even with native write on (seeVeloxDelta.md), so Delta checks their constraints, as before. Column-mapped tables on Spark 3.5 fall back to Delta's writer (apache#13383).Not covered. Once any constraint is not a top-level NOT NULL, all constraints are evaluated on the JVM, including top-level NOT NULLs, and a NOT NULL on a struct field exports the whole top-level struct. Checking NOT NULLs natively and exporting only the columns CHECKs reference would cut this further.
Measured with an earlier revision of this PR, on an 8-executor (4 cores each) Linux cluster, Spark 3.5, 24 GB off-heap per executor. The table has 64 files × 500K rows, a nested schema with ~600 leaf columns, a generated date partition, NOT NULL struct fields and change data feed on. A DELETE rewrites every file:
How was this patch tested?
DeltaNativeWriteSuite(Delta 3.3 and Delta 4) new tests: CHECK constraints unpartitioned and partitioned; nested NOT NULL (with a NULL parent) and generated columns; an empty partition string; DELETE with change data feed; an optimized write;replaceWhere, UPDATE and OPTIMIZE; legacy column invariants; a violation in a later batch of a task; CHECKs on decimal, TIMESTAMP_NTZ,current_date(), array and map columns. Each asserts the checker in the writer's plan and no row conversion of batches, and compares a violation's message with native write off.DeltaNativeWriteSuite20/20,GlutenDeltaInvariantCheckerSuite2/2 andGlutenDeltaNativeConstraintSuite6/6 pass.GlutenDeltaReferencedColumnsChecker, all 9 new constraint tests fail.DeleteSQLSuite,UpdateSQLSuite,DeltaInsertIntoDataFrameByPathSuite,DeltaColumnDefaultsInsertSuite,OptimizedWritesSuiteandDeltaSuitepass (279 tests).CheckConstraintsSuite,InvariantEnforcementSuite,GeneratedColumnSuite,TypeWideningConstraintsSuite,TypeWideningGeneratedColumnsSuite,DeltaColumnRenameSuite,DeltaDropColumnSuiteandOptimizeGeneratedColumnSuite, with Gluten loaded in every test session and native write on: nothing newly fails compared with the same bundle without the change. Their 51 common failures, all inOptimizeGeneratedColumnSuite, look for Delta's partition filters in a vanilla scan node. Of their native writes with constraints, 46 used the native checkers and 2 used Delta's row checker: writes that omit a NOT NULL column, which Delta rejects with its own error.🤖 Generated with Claude Code