[SPARK-58917][SQL] Respect inferSchema for variant ingestion in CSV parser - #58246
Open
pratham76 wants to merge 1 commit into
Open
[SPARK-58917][SQL] Respect inferSchema for variant ingestion in CSV parser#58246pratham76 wants to merge 1 commit into
pratham76 wants to merge 1 commit into
Conversation
ghanse
reviewed
Aug 24, 2026
Contributor
There was a problem hiding this comment.
@pratham76 I have already introduced this in #58175
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?
This PR adds a new CSV read option
variantRespectInferSchemathat controls type inference behavior for variant ingestion in the CSV parser. When enabled along with inferSchema=false, scalar CSV values are preserved as strings inside Variants instead of being automatically inferred to numeric or boolean types.Why are the changes needed?
Currently, the CSV to Variant parser (used by the singleVariantColumn option and explicit VariantType columns) always infers scalar types (long, decimal, date, timestamp, boolean) regardless of the inferSchema option. This means a value like "0001" is stored as the integer 1 rather than the string "0001", which may not be the desired behavior in all cases.
Users need a way to preserve the original string representation of CSV values when ingesting into Variants, particularly for:
Does this PR introduce any user-facing change?
Yes. This PR introduces a new CSV read option,
variantRespectInferSchema(default: false)How was this patch tested?
Added comprehensive tests in
CSVSuite, and added tests inCsvFunctionsSuitefor thefrom_csvfunctionWas this patch authored or co-authored using generative AI tooling?
No