[SPARK-44559][PYTHON][3.5] Improve error messages for Python UDTF arrow cast#42290
Closed
allisonwang-db wants to merge 1 commit intoapache:branch-3.5from
Closed
[SPARK-44559][PYTHON][3.5] Improve error messages for Python UDTF arrow cast#42290allisonwang-db wants to merge 1 commit intoapache:branch-3.5from
allisonwang-db wants to merge 1 commit intoapache:branch-3.5from
Conversation
This PR improves error messages when the output of an arrow-optimized Python UDTF cannot be casted to the specified return schema of the UDTF.
To make Python UDTFs more user-friendly.
Yes, before this PR, when the output of a UDTF fails to cast to the desired schema, Spark will throw this confusing error message:
```python
udtf(returnType="x: int")
class TestUDTF:
def eval(self):
yield [1, 2],
TestUDTF().collect()
```
```
File "pyarrow/array.pxi", line 1044, in pyarrow.lib.Array.from_pandas
File "pyarrow/array.pxi", line 316, in pyarrow.lib.array
File "pyarrow/array.pxi", line 83, in pyarrow.lib._ndarray_to_array
File "pyarrow/error.pxi", line 100, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Could not convert [1, 2] with type list: tried to convert to int32
```
Now, after this PR, the error message will look like this:
`pyspark.errors.exceptions.base.PySparkRuntimeError: [UDTF_ARROW_TYPE_CAST_ERROR] Cannot convert the output value of the column 'x' with type 'object' to the specified return type of the column: 'int32'. Please check if the data types match and try again.
`
New unit tests
Closes apache#42191 from allisonwang-db/spark-44559-arrow-cast.
Authored-by: allisonwang-db <allison.wang@databricks.com>
Signed-off-by: Takuya UESHIN <ueshin@databricks.com>
(cherry picked from commit 5384f46)
Signed-off-by: allisonwang-db <allison.wang@databricks.com>
HyukjinKwon
approved these changes
Aug 2, 2023
ueshin
approved these changes
Aug 2, 2023
Member
|
Thanks! merging to 3.5. |
ueshin
pushed a commit
that referenced
this pull request
Aug 2, 2023
…ow cast ### What changes were proposed in this pull request? This PR cherry-picks 5384f46. It improves error messages when the output of an arrow-optimized Python UDTF cannot be casted to the specified return schema of the UDTF. ### Why are the changes needed? To make Python UDTFs more user-friendly. ### Does this PR introduce _any_ user-facing change? Yes, before this PR, when the output of a UDTF fails to cast to the desired schema, Spark will throw this confusing error message: ```python udtf(returnType="x: int") class TestUDTF: def eval(self): yield [1, 2], TestUDTF().collect() ``` ``` File "pyarrow/array.pxi", line 1044, in pyarrow.lib.Array.from_pandas File "pyarrow/array.pxi", line 316, in pyarrow.lib.array File "pyarrow/array.pxi", line 83, in pyarrow.lib._ndarray_to_array File "pyarrow/error.pxi", line 100, in pyarrow.lib.check_status pyarrow.lib.ArrowInvalid: Could not convert [1, 2] with type list: tried to convert to int32 ``` Now, after this PR, the error message will look like this: `pyspark.errors.exceptions.base.PySparkRuntimeError: [UDTF_ARROW_TYPE_CAST_ERROR] Cannot convert the output value of the column 'x' with type 'object' to the specified return type of the column: 'int32'. Please check if the data types match and try again. ` ### How was this patch tested? New unit tests Closes #42290 from allisonwang-db/spark-44559-3.5. Authored-by: allisonwang-db <allison.wang@databricks.com> Signed-off-by: Takuya UESHIN <ueshin@databricks.com>
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 cherry-picks 5384f46. It improves error messages when the output of an arrow-optimized Python UDTF cannot be casted to the specified return schema of the UDTF.
Why are the changes needed?
To make Python UDTFs more user-friendly.
Does this PR introduce any user-facing change?
Yes, before this PR, when the output of a UDTF fails to cast to the desired schema, Spark will throw this confusing error message:
Now, after this PR, the error message will look like this:
pyspark.errors.exceptions.base.PySparkRuntimeError: [UDTF_ARROW_TYPE_CAST_ERROR] Cannot convert the output value of the column 'x' with type 'object' to the specified return type of the column: 'int32'. Please check if the data types match and try again.How was this patch tested?
New unit tests