`min` / `max` over a list of lists (or of structs) fails with "Internal error: Uncomparable values"
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
`ScalarValue::partial_cmp` for list values (`partial_cmp_list` in `datafusion/common/src/scalar/mod.rs`) compares the elements with the `arrow::compute::kernels::cmp::lt` / `eq` kernels. Those kernels reject nested element types, so the comparison returns `None` and callers report an internal error. `min` / `max` are the most visible callers, but anything that orders list scalars is affected.
### To Reproduce
```sql
SELECT min(column1), max(column1) FROM VALUES ([[1, 2]]), ([[1, 3]]);
```
```text
Internal error: Uncomparable values: List([[1, 2]]), List([[1, 3]]).
This issue was likely caused by a bug in DataFusion's code. Please help us to resolve this by filing a bug report in our issue tracker: https://github.com/apache/datafusion/issues
```
Same for a list of structs: `SELECT min(column1) FROM VALUES ([struct(1, 'a')]), ([struct(2, 'b')]);`
Comparing the same values with the binary operators (`[[1, 2]] < [[1, 3]]`) works, since that path uses the array comparison kernels directly.
### Expected behavior
Lists of nested values compare lexicographically like lists of primitives do, so `min` returns `[[1, 2]]` and `max` returns `[[1, 3]]`.
### Additional context
Found while running a corpus of aggregate queries over nested types against `datafusion-cli`.
Contributor guide
Research direction
Start in datafusion/common/src/scalar/mod.rs at ScalarValue::partial_cmp and partial_cmp_list, then trace the list comparison used by min and max. Add regression coverage for lists containing nested lists and structs, and verify the SQL examples return [[1, 2]] for min and [[1, 3]] for max without an internal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100