[SPARK-53330][SQL][PYTHON] Fix Arrow UDF with DayTimeIntervalType (bounds != start/end) #52077
+60
−3
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?
DayTimeIntervalType
s so that they are considered equal when the source type has more information than the target type. The arrow serialization always sends full intervals either way, so that should always be true. We can then rely on the engine to interpret the data according to the node's output type.Why are the changes needed?
When a pyspark udf (useArrow=true) returns interval type data, it currently errors with below error when the resultType (e.g., DayTimeIntervalType) has begin/end that don't span the maximum range.
org.apache.spark.SparkException: [ARROW_TYPE_MISMATCH] Invalid schema from pandas_udf(): expected DayTimeIntervalType(1,3), got DayTimeIntervalType(0,3). SQLSTATE: 42K0G
Repro:
The cause is that when the worker sends data back, it is always just sends a full arrow duration, which does not remember begin or end index. In above example, the begin should be
HOUR
(1), and that causes the node to throw said ARROW_TYPE_MISMATCH.YearToMonthIntervalType is not supported in arrow udfs, so that is currently not a concern.
Does this PR introduce any user-facing change?
Yes, a bug fix that enables behavior that previously threw an error.
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No