-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-45523][PYTHON] Return useful error message if UDTF returns Non…
…e for any non-nullable column ### What changes were proposed in this pull request? This PR updates Python UDTF evaluation to return a useful error message if UDTF returns None for any non-nullable column. This implementation also checks recursively for None values in subfields of array/struct/map columns as well. For example: ``` from pyspark.sql.functions import AnalyzeResult from pyspark.sql.types import ArrayType, IntegerType, StringType, StructType class Tvf: staticmethod def analyze(*args): return AnalyzeResult( schema=StructType() .add("result", ArrayType(IntegerType(), containsNull=False), True) ) def eval(self, *args): yield [1, 2, 3, 4], def terminate(self): yield [1, 2, None, 3], ``` ``` SELECT * FROM Tvf(TABLE(VALUES (0), (1))) > org.apache.spark.api.python.PythonException [UDTF_EXEC_ERROR] User defined table function encountered an error in the 'eval' or 'terminate' method: Column 0 within a returned row had a value of None, either directly or within array/struct/map subfields, but the corresponding column type was declared as non nullable; please update the UDTF to return a non-None value at this location or otherwise declare the column type as nullable. ``` ### Why are the changes needed? Previously this case returned a null pointer exception. ### Does this PR introduce _any_ user-facing change? Yes, see above. ### How was this patch tested? This PR adds new test coverage. ### Was this patch authored or co-authored using generative AI tooling? No Closes #43356 from dtenedor/improve-errors-null-checks. Authored-by: Daniel Tenedorio <daniel.tenedorio@databricks.com> Signed-off-by: Takuya UESHIN <ueshin@databricks.com>
- Loading branch information
Showing
6 changed files
with
626 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.