Skip to content

fix: compare nested list scalars with a dynamic comparator - #24938

Open
edubraqd wants to merge 2 commits into
apache:mainfrom
edubraqd:fix/nested-list-scalar-cmp
Open

fix: compare nested list scalars with a dynamic comparator#24938
edubraqd wants to merge 2 commits into
apache:mainfrom
edubraqd:fix/nested-list-scalar-cmp

Conversation

@edubraqd

@edubraqd edubraqd commented Sep 3, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

ScalarValue::partial_cmp for lists compared the elements with the lt / eq kernels, which reject nested element types, so min / max over a list of lists or a list of structs failed with Internal error: Uncomparable values.

What changes are included in this PR?

partial_cmp_list now compares the elements with arrow::array::make_comparator, which supports the nested types. nulls_first: false keeps the existing Postgres semantics where a NULL element is greater than a non-NULL one (this replaces the hand-written null checks), and the prefix / length rule is unchanged.

Are these changes tested?

Yes. test_nested_list_partial_cmp covers lists of lists (equal, less, greater, shorter prefix at both levels) and lists of structs; the existing test_list_partial_cmp and the rest of the scalar tests pass unchanged. aggregate.slt gains min / max over a list of lists and a list of structs.

Are there any user-facing changes?

min / max (and other list scalar comparisons) work for lists of nested values instead of returning an internal error.

`ScalarValue::partial_cmp` for lists compared the elements with the `lt` /
`eq` kernels, which reject nested element types. Any code path that compares
list scalars therefore failed for lists of lists or lists of structs, e.g.

    SELECT min(column1), max(column1) FROM VALUES ([[1, 2]]), ([[1, 3]]);
    Internal error: Uncomparable values: List([[1, 2]]), List([[1, 3]])

Use `make_comparator` for the element comparison instead. It supports the
nested types, and `nulls_first: false` keeps the existing Postgres semantics
where a NULL element is greater than a non-NULL one; the prefix / length rule
is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) common Related to common crate labels Sep 3, 2026
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant