Repository navigation
feat: add Spark equal_null, encode, to_binary, try_to_binary and stack - #1870
Open
slachiewicz wants to merge 1 commit into
Open
slachiewicz wants to merge 1 commit into
slachiewicz wants to merge 1 commit into
Conversation
slachiewicz
marked this pull request as ready for review
December 6, 2026 11:12
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?
Closes #1867.
Rationale for this change
datafusion-spark56 registersequal_null,to_binary,try_to_binary,encodeandstack, butdatafusion.functions.sparkhad no wrappers for them, so code ported from PySpark could not use them from the DataFrame API.What changes are included in this PR?
Adds five functions to
datafusion.functions.spark, with pyspark's parameter names:equal_null(col1, col2)encode(col, charset)to_binary(col, format=None)formatis"hex"(default),"utf-8","utf8"or"base64"try_to_binary(col, format=None)to_binary, but returns NULL instead of raising an errorstack(n, *cols)nrowsTwo points differ from pyspark:
to_binaryandtry_to_binary, a barestrforformatis the format itself, not a column name. The format must be a constant, so a column name could never work.stackreturns its rows as one list of structs with the fieldscol0,col1and so on, the same as upstream, so the caller unnests it.nmust be an integer literal.Each function has a docstring example and a test.
Open questions for review
formatas a literal. The module's rule for pyspark column-or-name parameters is that a barestrnames a column. I deviated because the format must be a constant. The alternative is to accept only anExprand requirelit("base64").try_to_binarywith an unknown format. It returns NULL, which is upstream's behavior and what the test asserts. I have not checked whether Spark itself returns NULL or raises in that case.stacksignature and result. pyspark's signature isstack(*cols); I named the first parameternfor readability, and positional calls behave the same. The result is a list of structs that the caller unnests; the wrapper could unnest for the caller instead, but then it would not be a plain expression.Are there any user-facing changes?
Yes, five new functions in
datafusion.functions.spark. Nothing existing changes.