[SPARK-55716][SQL][FOLLOWUP] Simplify NOT NULL preservation by skipping asNullable in resolveRelation#54597
Open
yaooqinn wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-55716][SQL][FOLLOWUP] Simplify NOT NULL preservation by skipping asNullable in resolveRelation#54597yaooqinn wants to merge 1 commit intoapache:masterfrom
yaooqinn wants to merge 1 commit intoapache:masterfrom
Conversation
…ng asNullable in resolveRelation Instead of calling `dataSchema.asNullable` in `resolveRelation()` and then restoring nullability from the user schema in `CreateDataSourceTableCommand`, add a `forceNullable` parameter to `resolveRelation()` and pass `false` from the create-table path. This eliminates the `restoreNullability` and `restoreDataTypeNullability` helper methods, simplifying the code significantly (-37 lines net). The read path is unaffected: `resolveRelation()` defaults to `forceNullable = true` (preserving SPARK-13738 safety). Only the create-table path skips `asNullable` so the catalog stores the user's original nullability constraints. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 were proposed in this pull request?
Followup to #54517. Simplifies NOT NULL constraint preservation per review feedback.
Instead of calling
dataSchema.asNullableinresolveRelation()and then restoring nullability with recursiverestoreNullability/restoreDataTypeNullabilityhelpers inCreateDataSourceTableCommand, this PR:forceNullableparameter toDataSource.resolveRelation()(defaulttrue, preserving existing behavior)forceNullable = !enforceNotNullfromCreateDataSourceTableCommand, soasNullableis skipped only when the config is enabledrestoreNullabilityandrestoreDataTypeNullabilityhelper methods entirelyData flow:
forceNullable = true→asNullableruns → same behavior as before SPARK-55716forceNullable = false→asNullableskipped → catalog stores NOT NULL →PreprocessTableInsertionenforces at insert timeWhy are the changes needed?
Addresses review feedback: "is it simpler to not do
dataSchema.asNullableif the flag is on?"Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing SPARK-55716 tests (7 tests in InsertSuite) and ShowCreateTableSuite (30 tests) all pass.
Was this patch authored or co-authored using generative AI tooling?
Yes, co-authored with GitHub Copilot.