[SPARK-47628][SQL] Fix Postgres bit array issue 'Cannot cast to boolean'#45751
Closed
yaooqinn wants to merge 2 commits intoapache:masterfrom
Closed
[SPARK-47628][SQL] Fix Postgres bit array issue 'Cannot cast to boolean'#45751yaooqinn wants to merge 2 commits intoapache:masterfrom
yaooqinn wants to merge 2 commits intoapache:masterfrom
Conversation
Member
Author
|
cc @dongjoon-hyun @cloud-fan, thanks |
dongjoon-hyun
approved these changes
Mar 28, 2024
Member
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM. Thank you, @yaooqinn .
Merged to master for Apache Spark 4.0.0.
cloud-fan
reviewed
Apr 3, 2024
| md: MetadataBuilder): Option[DataType] = typeName match { | ||
| case "bool" => Some(BooleanType) | ||
| case "bit" => Some(BinaryType) | ||
| case "bit" if precision == 1 => Some(BooleanType) |
Contributor
There was a problem hiding this comment.
is it possible to keep the previous type mapping and only fix the read code? It seems a bit weird to me to have different type mapping based on the bit length.
Member
Author
There was a problem hiding this comment.
- This aligns atomic bit(1), see https://github.com/apache/spark/pull/45751/files#diff-374d2da08d88160979e0fedb2ded14e5fa8ed04942a94cdd9672775332642226L55
- pgjdbc has a boolean array decoder for bit(1)[], while it also wrongly tries to decode bit(n)[] anyway.
Contributor
There was a problem hiding this comment.
This aligns atomic bit(1), see ...
I see, internal consistency is important.
Member
Author
There was a problem hiding this comment.
Thank you for the double-check and post-review. @cloud-fan
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 fixes the below error when reading the bit array from Postgres.
The issue is caused by both an upstream limitation and an improper mapping on our side.
The issue of Postges' own is that it does not distinguish bit(1) and bit(n>1) arrays and gets them both as boolean arrays, which causes a cast error on our task execution side.
The issue of our own is similar. We map both bit(1)[] and bit(n>1)[] as
ArrayType(BinaryType). It is exactly the opposite of Postgres' behaviour.This PR fixes the mapping and makes a special getter for bit(n>1)[] values to fix both of the problems
Why are the changes needed?
bugfix
Does this PR introduce any user-facing change?
no
How was this patch tested?
new tests
Was this patch authored or co-authored using generative AI tooling?
no