feat: Implement Spark bin function#20479
Open
kazantsev-maksim wants to merge 12 commits intoapache:mainfrom
Open
feat: Implement Spark bin function#20479kazantsev-maksim wants to merge 12 commits intoapache:mainfrom
bin function#20479kazantsev-maksim wants to merge 12 commits intoapache:mainfrom
Conversation
added 3 commits
February 22, 2026 19:52
Jefffrey
reviewed
Feb 23, 2026
jonathanc-n
reviewed
Feb 23, 2026
| ## PySpark 3.5.5 Result: {'bin(13.3)': '1101', 'typeof(bin(13.3))': 'string', 'typeof(13.3)': 'decimal(3,1)'} | ||
| #query | ||
| #SELECT bin(13.3::decimal(3,1)); | ||
| query T |
Contributor
There was a problem hiding this comment.
We should try to add some null handling test cases + handling actual table columns
| #SELECT bin(13::int); | ||
|
|
||
| ## Original Query: SELECT bin(13.3); | ||
| ## PySpark 3.5.5 Result: {'bin(13.3)': '1101', 'typeof(bin(13.3))': 'string', 'typeof(13.3)': 'decimal(3,1)'} |
Contributor
There was a problem hiding this comment.
Spark supports decimal, we should add this support to this PR as well
martin-g
reviewed
Feb 23, 2026
Member
There was a problem hiding this comment.
This could use coercible signature instead:
let int64 = Coercion::new_implicit(
TypeSignatureClass::Native(logical_int64()),
vec![TypeSignatureClass::Numeric],
NativeType::Int64,
);
TypeSignature::Coercible(vec![int64])
Member
There was a problem hiding this comment.
Actually Spark's bin() supports even floating numbers:
spark-sql (default)> select bin(13);
1101
Time taken: 0.785 seconds, Fetched 1 row(s)
spark-sql (default)> select bin(-13);
1111111111111111111111111111111111111111111111111111111111110011
Time taken: 0.032 seconds, Fetched 1 row(s)
spark-sql (default)> select bin(13.3);
1101
Time taken: 0.04 seconds, Fetched 1 row(s)
The function documentation says: "Returns the string representation of the long value expr represented in binary"
So, it should use logical_number above
Contributor
Author
|
@martin-g @Jefffrey @jonathanc-n Thanks for the review! |
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.
Which issue does this PR close?
N/A
Rationale for this change
Add new function: https://spark.apache.org/docs/latest/api/sql/index.html#bin
What changes are included in this PR?
Are these changes tested?
Yes, tests added as part of this PR.
Are there any user-facing changes?
No, these are new function.