Commit fc6d0a4
authored
Fix shuffle function to report nullability correctly (#19184)
# fix: shuffle should report nullability correctly
- Replace return_type with return_field_from_args to preserve input
nullability
- Add test to verify nullability is correctly reported
- Addresses issue #19145
## Which issue does this PR close?
Closes #19145
## Rationale for this change
The `shuffle` UDF was using the default `is_nullable` implementation
which always returns `true`, regardless of the input array's
nullability. This causes:
1. Incorrect schema inference - non-nullable inputs are incorrectly
marked as nullable
2. Missed optimization opportunities - the query optimizer cannot apply
certain optimizations when nullability information is incorrect
3. Potential runtime errors - incorrect metadata can lead to unexpected
behavior in downstream operations
The shuffle function simply reorders elements within an array without
changing the array's structure or nullability, so the output should have
the same nullability as the input.
## What changes are included in this PR?
1. **Implemented `return_field_from_args`**: Returns the input field
directly, preserving both data type and nullability
2. **Updated `return_type`**: Now returns an error directing users to
use `return_field_from_args` instead (following DataFusion best
practices)
3. **Added comprehensive tests**: Verifies that both nullable and
non-nullable inputs are handled correctly
## Are these changes tested?
Yes, this PR includes a new test `test_shuffle_nullability` that
verifies:
- Non-nullable array input produces non-nullable output
- Nullable array input produces nullable output
- Data types are preserved correctly in both cases
Test results:1 parent cb2f3d2 commit fc6d0a4
1 file changed
+61
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | | - | |
91 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
| |||
263 | 273 | | |
264 | 274 | | |
265 | 275 | | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
0 commit comments