Skip to content

[SPARK-55723][PYTHON] Generalize enforce_schema error to PySparkTypeError#54736

Open
Yicong-Huang wants to merge 1 commit intoapache:masterfrom
Yicong-Huang:SPARK-55723/fix/enforce-schema-error
Open

[SPARK-55723][PYTHON] Generalize enforce_schema error to PySparkTypeError#54736
Yicong-Huang wants to merge 1 commit intoapache:masterfrom
Yicong-Huang:SPARK-55723/fix/enforce-schema-error

Conversation

@Yicong-Huang
Copy link
Contributor

@Yicong-Huang Yicong-Huang commented Mar 10, 2026

What changes were proposed in this pull request?

Replace PySparkRuntimeError with RESULT_COLUMNS_MISMATCH_FOR_ARROW_UDTF error class in enforce_schema and ArrowStreamArrowUDTFSerializer with a general PySparkTypeError that reports column name, expected type, and actual type without being specific to any UDF type.

Why are the changes needed?

The RESULT_COLUMNS_MISMATCH_FOR_ARROW_UDTF error class was UDTF-specific, but enforce_schema is a general utility used across UDF types. The error message ("Column names ... do not match specified schema") was also misleading -- the actual failure is a type cast error, not a column name mismatch.

Does this PR introduce any user-facing change?

Yes. The error type changes from PySparkRuntimeError to PySparkTypeError, and the message now accurately describes the type mismatch:

Before:

PySparkRuntimeError: [RESULT_COLUMNS_MISMATCH_FOR_ARROW_UDTF] Column names of the returned pyarrow.Table or pyarrow.RecordBatch do not match specified schema. Expected: int32 Actual: string

After:

PySparkTypeError: Result type of column 'id' does not match the expected type. Expected: int32, got: string.

How was this patch tested?

Updated existing test in test_arrow_udtf.py.

Was this patch authored or co-authored using generative AI tooling?

No

@Yicong-Huang
Copy link
Contributor Author

cc @gaogaotiantian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant