[SPARK-55583][PYTHON] Validate Arrow schema types in Python data source#54362
Open
Yicong-Huang wants to merge 3 commits intoapache:masterfrom
Open
[SPARK-55583][PYTHON] Validate Arrow schema types in Python data source#54362Yicong-Huang wants to merge 3 commits intoapache:masterfrom
Yicong-Huang wants to merge 3 commits intoapache:masterfrom
Conversation
Contributor
Author
3e695b7 to
1055807
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 were proposed in this pull request?
This PR adds Arrow schema type validation for the
pa.RecordBatchcode path in Python data source reads. The fix adds apa_schema.equals(first_element.schema)check after the existing column name validation inrecords_to_arrow_batches(), raising a clearDATA_SOURCE_RETURN_SCHEMA_MISMATCHerror with the expected and actual Arrow schemas.Why are the changes needed?
When a Python data source returns a
pa.RecordBatchwith data types that don't match the declared schema, the resulting JVM-side errors are confusing and do not indicate the root cause. For example:IllegalArgumentException: not all nodes, buffers and variadicBufferCounts were consumedfromVectorLoader.load()UnsupportedOperationException: Cannot call the method "getUTF8String" of ArrowColumnVector$ArrowVectorAccessorThese errors give no indication that the issue is a schema type mismatch in the Python data source's
read()method.Does this PR introduce any user-facing change?
Yes. Previously, returning a
pa.RecordBatchwith mismatched types from a Python data source would result in cryptic JVM errors. Now it raises a clearDATA_SOURCE_RETURN_SCHEMA_MISMATCHerror showing the expected and actual Arrow schemas.How was this patch tested?
Added a test case in
test_python_datasource.py::test_arrow_batch_data_source.Was this patch authored or co-authored using generative AI tooling?
No