-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21692][PYSPARK][SQL] Add nullability support to PythonUDF. #18906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ed5e453
Add nullability support.
ptkool ca63b8f
Additional changes for panda UDFs
ptkool 71c23de
Fix Python test failures
ptkool d2d06d3
Undo change to modules.py
ptkool 90e1684
Resolve conflicts
ptkool 0727597
Fix Python style tests
ptkool f8e4904
Resolve test failures
ptkool d992f93
Make Python API consistent with Scala API
ptkool ca52538
Fix test failures
ptkool 9a11aa9
Clean up and small corrections based on feedback
ptkool 0bb9472
More changes based on feedback
ptkool 6348f05
Resolve conflicts
ptkool 592324d
Resolve conflicts
ptkool 5af8e57
Changes based on feedback
ptkool 414545d
Fix Python style errors
ptkool 3b72f0d
Documentation corrections
ptkool d52e1f0
Changed version added to 2.4
ptkool e94960c
Raise exceptions for non-nullable functions returning null values
ptkool e6e6dbf
Fix tests and Python style checks
ptkool 64f0500
Merge branch 'master' into udf_nullability
ptkool cdd16a9
Resolve conflicts
ptkool 9038520
Fix test failures
ptkool dcf3f07
Fix generated code compilation failures
ptkool 97305f5
Fix failing ML tests
ptkool 0377e28
Merge branch 'master' into udf_nullability
ptkool fac6f1e
Fix compilation failure when running Pandas tests
ptkool eebc18f
Rebase and add udf tests to proper modules
ptkool e1d68e8
Fix merge conflicts
ptkool be5735a
Fix compilation errors
ptkool 9cfc5b6
Resolve merge conflict
ptkool b074eb1
Fix merge conflicts
ptkool 516a708
Fix test failures
ptkool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ def _create_udf(f, returnType, evalType): | |
|
|
||
| # Set the name of the UserDefinedFunction object to be the name of function f | ||
| udf_obj = UserDefinedFunction( | ||
| f, returnType=returnType, name=None, evalType=evalType, deterministic=True) | ||
| f, returnType=returnType, name=None, evalType=evalType, deterministic=True, nullable=True) | ||
| return udf_obj._wrapped() | ||
|
|
||
|
|
||
|
|
@@ -93,7 +93,8 @@ def __init__(self, func, | |
| returnType=StringType(), | ||
| name=None, | ||
| evalType=PythonEvalType.SQL_BATCHED_UDF, | ||
| deterministic=True): | ||
| deterministic=True, | ||
| nullable=True): | ||
| if not callable(func): | ||
| raise TypeError( | ||
| "Invalid function: not a function or callable (__call__ is not defined): " | ||
|
|
@@ -118,6 +119,7 @@ def __init__(self, func, | |
| else func.__class__.__name__) | ||
| self.evalType = evalType | ||
| self.deterministic = deterministic | ||
| self.nullable = nullable | ||
|
|
||
| @property | ||
| def returnType(self): | ||
|
|
@@ -202,7 +204,7 @@ def _create_judf(self): | |
| wrapped_func = _wrap_function(sc, self.func, self.returnType) | ||
| jdt = spark._jsparkSession.parseDataType(self.returnType.json()) | ||
| judf = sc._jvm.org.apache.spark.sql.execution.python.UserDefinedPythonFunction( | ||
| self._name, wrapped_func, jdt, self.evalType, self.deterministic) | ||
| self._name, wrapped_func, jdt, self.evalType, self.deterministic, self.nullable) | ||
| return judf | ||
|
|
||
| def __call__(self, *cols): | ||
|
|
@@ -240,11 +242,14 @@ def wrapper(*args): | |
| wrapper.deterministic = self.deterministic | ||
| wrapper.asNondeterministic = functools.wraps( | ||
| self.asNondeterministic)(lambda: self.asNondeterministic()._wrapped()) | ||
| wrapper.asNonNullable = functools.wraps( | ||
| self.asNonNullable)(lambda: self.asNonNullable()._wrapped()) | ||
| wrapper.nullable = self.nullable | ||
| return wrapper | ||
|
|
||
| def asNondeterministic(self): | ||
| """ | ||
| Updates UserDefinedFunction to nondeterministic. | ||
| Updates :class:`UserDefinedFunction` to nondeterministic. | ||
|
|
||
| .. versionadded:: 2.3 | ||
| """ | ||
|
|
@@ -254,6 +259,15 @@ def asNondeterministic(self): | |
| self.deterministic = False | ||
| return self | ||
|
|
||
| def asNonNullable(self): | ||
| """ | ||
| Updates :class:`UserDefinedFunction` to non-nullable. | ||
|
|
||
| .. versionadded:: 2.4 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do this 2.3.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3.0? |
||
| """ | ||
| self.nullable = False | ||
| return self | ||
|
|
||
|
|
||
| class UDFRegistration(object): | ||
| """ | ||
|
|
@@ -371,7 +385,8 @@ def register(self, name, f, returnType=None): | |
| "SQL_MAP_PANDAS_ITER_UDF.") | ||
| register_udf = UserDefinedFunction(f.func, returnType=f.returnType, name=name, | ||
| evalType=f.evalType, | ||
| deterministic=f.deterministic) | ||
| deterministic=f.deterministic, | ||
| nullable=f.nullable) | ||
| return_udf = f | ||
| else: | ||
| if returnType is None: | ||
|
|
||
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.