This is an automated email from the ASF dual-hosted git repository.
allisonwang pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new bc1bbe6eb06e [SPARK-55525][PYTHON] Fix
UDTF_ARROW_TYPE_CONVERSION_ERROR with undefined error message parameter
bc1bbe6eb06e is described below
commit bc1bbe6eb06eaf2faab730743b61b3a848a49c3f
Author: Allison Wang <[email protected]>
AuthorDate: Mon Feb 23 11:44:40 2026 -0800
[SPARK-55525][PYTHON] Fix UDTF_ARROW_TYPE_CONVERSION_ERROR with undefined
error message parameter
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines:
https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR:
https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g.,
'[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a
faster review.
7. If you want to add a new configuration, please read the guideline
first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the
guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section
is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster
reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class
hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other
DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
There is a mismatch between the error class definition for
UDTF_ARROW_TYPE_CONVERSION_ERROR and its usage. The code in
python/pyspark/worker.py was raising UDTF_ARROW_TYPE_CONVERSION_ERROR with
parameters data, schema, and arrow_schema, but the error class definition in
error-conditions.json did not expect any parameters. This PR fixed this by
introducing a new error class UDTF_ARROW_DATA_CONVERSION_ERROR specifically for
data conversion errors, which accepts the necessary parameters.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
Fixing a bug
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as
new features, bug fixes, or other behavior changes. Documentation-only updates
are not considered user-facing changes.
If yes, please clarify the previous behavior and the change this PR
proposes - provide the console output, description and/or an example to show
the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared
to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some
test cases that check the changes thoroughly including negative and positive
cases if possible.
If it was tested in a way different from regular unit tests, please clarify
how you tested step by step, ideally copy and paste-able, so that other
reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why
it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions
for the consistent environment, and the instructions could accord to:
https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
uT
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this
patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
Yes
Closes #54318 from allisonwang-db/fix-udtf-error.
Authored-by: Allison Wang <[email protected]>
Signed-off-by: Allison Wang <[email protected]>
(cherry picked from commit e7de36212cb109c271d6b4018760a2757886935a)
Signed-off-by: Allison Wang <[email protected]>
---
python/pyspark/errors/error-conditions.json | 5 +++++
python/pyspark/sql/tests/arrow/test_arrow_udtf.py | 17 +++++++++++++++++
python/pyspark/sql/tests/test_udtf.py | 16 ++++++++--------
python/pyspark/worker.py | 2 +-
4 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/python/pyspark/errors/error-conditions.json
b/python/pyspark/errors/error-conditions.json
index 326671c0d5ad..da8a9f1fea34 100644
--- a/python/pyspark/errors/error-conditions.json
+++ b/python/pyspark/errors/error-conditions.json
@@ -1187,6 +1187,11 @@
"Return type of the user-defined function should be <expected>, but is
<actual>."
]
},
+ "UDTF_ARROW_DATA_CONVERSION_ERROR": {
+ "message": [
+ "Cannot convert UDTF output to Arrow. Data: <data>. Schema: <schema>.
Arrow Schema: <arrow_schema>."
+ ]
+ },
"UDTF_ARROW_TYPE_CAST_ERROR": {
"message": [
"Cannot convert the output value of the column '<col_name>' with type
'<col_type>' to the specified return type of the column: '<arrow_type>'. Please
check if the data types match and try again."
diff --git a/python/pyspark/sql/tests/arrow/test_arrow_udtf.py
b/python/pyspark/sql/tests/arrow/test_arrow_udtf.py
index cc0edda378ab..2be399171abb 100644
--- a/python/pyspark/sql/tests/arrow/test_arrow_udtf.py
+++ b/python/pyspark/sql/tests/arrow/test_arrow_udtf.py
@@ -33,6 +33,23 @@ if have_pyarrow:
@unittest.skipIf(not have_pyarrow, pyarrow_requirement_message)
class ArrowUDTFTestsMixin:
+ def test_arrow_udtf_data_conversion_error(self):
+ from pyspark.sql.functions import udtf
+
+ @udtf(returnType="x int, y int")
+ class DataConversionErrorUDTF:
+ def eval(self):
+ # Return a non-tuple value when multiple return values are
expected.
+ # This will cause LocalDataToArrowConversion.convert to fail
with TypeError (len() on int),
+ # which should be wrapped in UDTF_ARROW_DATA_CONVERSION_ERROR.
+ yield 1
+
+ # Enable Arrow optimization for regular UDTFs
+ with self.sql_conf({"spark.sql.execution.pythonUDTF.arrow.enabled":
"true"}):
+ with self.assertRaisesRegex(PythonException,
"UDTF_ARROW_DATA_CONVERSION_ERROR"):
+ result_df = DataConversionErrorUDTF()
+ result_df.collect()
+
def test_arrow_udtf_zero_args(self):
@arrow_udtf(returnType="id int, value string")
class TestUDTF:
diff --git a/python/pyspark/sql/tests/test_udtf.py
b/python/pyspark/sql/tests/test_udtf.py
index 5ded5aa67b4e..54bd2a34ff1d 100644
--- a/python/pyspark/sql/tests/test_udtf.py
+++ b/python/pyspark/sql/tests/test_udtf.py
@@ -3548,7 +3548,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield 1,
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
@@ -3575,7 +3575,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield "1",
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
@@ -3604,7 +3604,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield "hello",
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
("x: tinyint", err),
@@ -3632,7 +3632,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield [0, 1.1, 2],
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
("x: tinyint", err),
@@ -3664,7 +3664,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield {"a": 0, "b": 1.1, "c": 2},
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
("x: tinyint", err),
@@ -3695,7 +3695,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield {"a": 0, "b": 1.1, "c": 2},
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
("x: tinyint", err),
@@ -3725,7 +3725,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
def eval(self):
yield Row(a=0, b=1.1, c=2),
- err = "UDTF_ARROW_TYPE_CONVERSION_ERROR"
+ err = "UDTF_ARROW_DATA_CONVERSION_ERROR"
for ret_type, expected in [
("x: boolean", err),
("x: tinyint", err),
@@ -3761,7 +3761,7 @@ class UDTFArrowTestsMixin(LegacyUDTFArrowTestsMixin):
"x: array<int>",
]:
with self.subTest(ret_type=ret_type):
- with self.assertRaisesRegex(PythonException,
"UDTF_ARROW_TYPE_CONVERSION_ERROR"):
+ with self.assertRaisesRegex(PythonException,
"UDTF_ARROW_DATA_CONVERSION_ERROR"):
udtf(TestUDTF, returnType=ret_type)().collect()
def test_decimal_round(self):
diff --git a/python/pyspark/worker.py b/python/pyspark/worker.py
index 4bae9f6dc48f..fe68b8baa6c9 100644
--- a/python/pyspark/worker.py
+++ b/python/pyspark/worker.py
@@ -2342,7 +2342,7 @@ def read_udtf(pickleSer, infile, eval_type):
def raise_conversion_error(original_exception):
raise PySparkRuntimeError(
- errorClass="UDTF_ARROW_TYPE_CONVERSION_ERROR",
+ errorClass="UDTF_ARROW_DATA_CONVERSION_ERROR",
messageParameters={
"data": str(data),
"schema": return_type.simpleString(),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]