Commit 8d3e10a
authored
feat: auto-enable invariants writer feature for non-null columns in CREATE TABLE (#2418)
## What changes are proposed in this pull request?
Auto-adds the invariants writer feature to the protocol when a CREATE
TABLE schema contains any user-controlled non-null field (nullable:
false). Delta-Spark treats non-nullable schema columns as implicit
invariants and requires this feature to be listed in writerFeatures.
Previously kernel rejected non-null columns at CREATE; this change makes
such tables compatible with Spark readers/writers.
Explicit delta.invariants metadata annotations (SQL expression
invariants like x > 3) remain rejected because kernel cannot evaluate
them. The existing write guard in
TableConfiguration::ensure_write_supported blocks writes to any table
with such metadata; we now reject it at CREATE time for a clearer,
path-aware error.
Also adds TableFeature::Invariants to ALLOWED_DELTA_FEATURES so users
can pre-enable the feature on an all-nullable table via
delta.feature.invariants=supported. This is useful when a later ALTER
TABLE ADD COLUMN NOT NULL (by Spark) should not need a protocol upgrade.
Core changes:
- validate_schema_for_create no longer takes invariants_enabled and
instead rejects fields with delta.invariants metadata
- New schema_contains_non_null_fields helper
- New maybe_enable_invariants in the CREATE builder, following the
maybe_enable_variant_type / maybe_enable_timestamp_ntz pattern; adds
schema driven Invariants to writer_features only
- TableFeature::Invariants added to ALLOWED_DELTA_FEATURES
## How was this change tested?
- Unit: schema_contains_non_null_fields (top-level, nested, array, map,
all-nullable, Variant-skip), test_maybe_enable_invariants (feature flips
on for non-null only), invariants_metadata_rejected (all nesting paths),
and invariants case in test_feature_signal_accepted
- Integration:
test_create_table_with_non_null_columns_auto_enables_invariants,
test_create_table_with_invariants_feature_signal_allowed,
test_create_table_rejects_delta_invariants_metadata
- Full cargo test -p delta_kernel --all-features --locked --lib --tests
passes
- cargo clippy --tests --benches -- -D warnings clean
Co-authored-by: Sanuj Basu <sanujbasu@users.noreply.github.com>1 parent af7f316 commit 8d3e10a
5 files changed
Lines changed: 382 additions & 136 deletions
File tree
- kernel
- src
- schema
- transaction/builder
- tests/create_table
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| |||
1291 | 1291 | | |
1292 | 1292 | | |
1293 | 1293 | | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
1294 | 1328 | | |
1295 | 1329 | | |
1296 | 1330 | | |
| |||
2733 | 2767 | | |
2734 | 2768 | | |
2735 | 2769 | | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
2736 | 2834 | | |
2737 | 2835 | | |
2738 | 2836 | | |
| |||
0 commit comments