Repository navigation
Support comparing arrays on bigger sizes with no supertype conversion(64, 128, 256 bits) operators( =, !=, >, >=, <, <=, IS DISTINCT FROM, IS NOT DISTINCT FROM) - #110245
Conversation
|
Workflow [PR], commit [3d91f77] Summary: ✅
AI ReviewSummaryThis PR adds a lexicographic fallback for array comparisons whose element types have no least common supertype, extends the same family of no-supertype handling to the null-safe comparison wrappers, and adds focused regressions for wide signed/unsigned integers, nested nullability, and the Missing context / blind spots
Final Verdict✅ No blocking issues found in the current head. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 325/326 (99.69%) · Uncovered code |
11c6cca to
0c7b370
Compare
0c7b370 to
d19c8b9
Compare
…plate generation expansion)
…r arrayExecute since previous implementation did not build on amd_binary and arm_binary
Fgrtue
left a comment
There was a problem hiding this comment.
I think the implementation of the algorithm is good and I have no questions to it. The code is understandable and easy to read, the comments also help.
I have one suggestion in terms of the design, and I also have a test case that seemed not to work for me:
SELECT [tuple(1::Nullable(Int64))] < [tuple(1::Nullable(UInt64))];
However the version without arrays works fine:
SELECT tuple(1::Nullable(Int64)) < tuple(1::Nullable(UInt64))
Good catch! At some point I tried to discuss this with claude and checked the code. It would be difficult to allow this query to work because the null-safe code on NullSafeCmp only allow comparisons without order, The equality comparison works like in the query below: It works because it uses the code from FunctionComparison<EqualsOp, NameEquals, true>::executeTupleImpl which composes tuple fields with FunctionIsNotDistinctFrom that propagate null-safety through the recursion. To support the comparison query it would require changes as big as this PR, because once you do it, you have to guarantee order between NULLs. We could maybe leave this as an issue for a future PR. |
…truct to represent comparable array columns
|
The failure in Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) is a known flaky signature, not a deterministic test assertion from this PR: Job link: https://github.com/ClickHouse/ClickHouse/actions/runs/30459583353/job/90868375171?pr=110245 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 342/343 (99.71%) · Uncovered code |
Fgrtue
left a comment
There was a problem hiding this comment.
I really liked reading through the code. Everything looks modular and is was easy to decouple the logic. I made just two suggestions about using constexpr. Other than that I don't have any more suggestion that I find in any way significant. If you decide to make those changes and decide to keep the current implementation without any other changes -- please feel free to merge, because green mark from me would be just a formality after all (:
4b1308e
Comparing two arrays whose element types have no least supertype takes the element-wise lexicographic path added by ClickHouse#110245. When a position holds a bare `Nothing`, `getReturnTypeImpl` declared a plain `UInt8` while the executing element comparator declared `Nothing`, so the unconditional `assert_cast<const ColumnUInt8 &>` on the element result received a `ColumnNothing` and killed the server: SELECT CAST([], 'Array(Nullable(Nothing))') > [[1]]; Logical error: 'Bad cast from type DB::ColumnNothing to DB::ColumnVector<char8_t>' The divergence exists because validation recurses into `getReturnTypeImpl` directly, which has no `Nothing` handling, while execution goes through the overload resolver, which short-circuits to `DataTypeNothing`. It is reachable from ordinary SQL, both during constant folding and at runtime over a table, and through `Tuple` members at any array depth. Close it from both ends. Validation now rejects a position that nothing can decide: a bare `Nothing`, directly or through a `Tuple` member. Two `Nothing` shapes stay decidable and keep answering as they do today -- `Nullable(Nothing)` is decided by its own all-set null map, and `Array(Nothing)` shares a supertype with `Array(T)` so it never reaches this branch. Each side is classified independently, because one side's null map never decides a position on the other side. `Array` and `Map` are not descended, matching `FunctionsNullSafeCmp::containsNothing`; depth is still covered because the array branch recurses once per level and is only consulted where that level has no supertype. Execution answers what validation accepted and fails closed otherwise: a result is synthesised only where a direct `Nothing` argument is paired with its own all-set null map, and any other `Nothing` element type throws instead of fabricating a `false`. The direct-recursion optimisation is kept. An untyped NULL or empty array against a non-supertypable partner now answers instead of aborting, matching the supertype path. The regression never shipped in a release.
Comparing two arrays whose element types have no least common supertype would previously threw
ILLEGAL_TYPE_OF_ARGUMENT.Reproduced on mixed signed/unsigned integers wider than 32 bits, such as
Array(Int64)vsArray(UInt64)orArray(Int256)vsArray(UInt256). This happened because the array comparison path relied ongetLeastSupertypeto bring both sides to a common bigger element type, and no such type exists for those combinations.This change adds
executeArraypath. Additionally, there is a templated version ofexecuteArrayfor each operator and it calls the specificexecuteArrayLexicographicImpl.Closes: #33897
At execution time
executeArraycompares the arrays lexicographically:equals(and, for ordering operators,less/greater) comparisons are run once over all gathered elements at once.The path works for constant and non-constant columns, empty arrays, and nested arrays (
Array(Array(...))).Tests
Added
04509_array_comparison_bigger_typesand04538_null_safe_cmp_bigger_typescovering all six comparison operators,IS DISTINCT FROMandIS NOT DISTINCT FROM, mixed signed/unsigned 64-bit and 256-bit element types, length tie-breaking, empty arrays, nested arrays, per-row offsets via a table, incomparable element types still throw.Changelog category (leave one):
Changelog entry:
Fixes comparisons that previously threw
ILLEGAL_TYPE_OF_ARGUMENTwhen the operands have no least common supertype. Arrays such asArray(Int64)vsArray(UInt64)andArray(Int256)vsArray(UInt256)can now be compared lexicographically with=,!=,<,<=,>,>=,IS DISTINCT FROM, andIS NOT DISTINCT FROM. Null-safe comparisons such asisDistinctFrom/isNotDistinctFromnow also compare supported non-array numeric or decimal pairs by value instead of throwing.` Array comparison with nested type = Tuple(Nullable(...)) works for equality.Version info
26.8.1.817(included in26.8and later)