datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

`min` / `max` over a list of lists (or of structs) fails with "Internal error: Uncomparable values"

Open edubraqd opened this issue 3 months ago • 1 comments

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

SELECT min(column1), max(column1) FROM VALUES ([[1, 2]]), ([[1, 3]]);
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.

edubraqd avatar Sep 03 '26 23:09 edubraqd

This sounds very useful

comphead avatar Oct 22 '26 16:10 comphead