Skip to content

Commit 1d24a24

Browse files
Fix tuple comparison type inference returning Nullable(Nothing) instead of Nullable(UInt8)
When comparing tuples where one element comparison involves `Nothing` type (e.g., `equals(Tuple(Nullable(UInt16), Nullable(String)), Nullable(Tuple(Nullable(Nothing), String)))`), the type inference for the comparison result was returning `Nullable(Nothing)` or bare `Nothing`. However, comparison functions always produce `UInt8` results at execution time (wrapped in `Nullable` when needed), so the actual column type was `Nullable(UInt8)`. This type mismatch between the inferred header type and actual data type caused an `assertTypeEquality` exception in `MergingSortedAlgorithm` when merging sorted streams from `GROUPING SETS`, because `MergedData` was initialized from the header with `ColumnNullable(ColumnNothing, ...)` but the actual data had `ColumnNullable(ColumnUInt8, ...)`. The fix ensures that tuple comparison type inference always returns `Nullable(UInt8)` instead of `Nullable(Nothing)` or `Nothing` when element comparisons produce null/nothing results, matching the actual execution behavior. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=305cb0a8d1e26c4db22fec8e634121fca6c9e358&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_msan%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent e090ba2 commit 1d24a24

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎src/Functions/FunctionsComparison.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,15 +1298,15 @@ class FunctionComparison : public IFunction
12981298
}
12991299

13001300
if (has_nothing)
1301-
return std::make_shared<DataTypeNothing>();
1301+
return std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt8>());
13021302

13031303
// In null-safe cmp mode, return DataTypeUInt8
13041304
if (is_null_safe_cmp_mode)
13051305
return std::make_shared<DataTypeUInt8>();
13061306
/// If any element comparison is nullable, return type will also be nullable.
13071307
/// We useDefaultImplementationForNulls, but it doesn't work for tuples.
13081308
if (has_null)
1309-
return std::make_shared<DataTypeNullable>(std::make_shared<DataTypeNothing>());
1309+
return std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt8>());
13101310
if (has_nullable)
13111311
return std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt8>());
13121312
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
\N
2+
\N
3+
Nullable(UInt8)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Tuple comparison involving Nullable(Nothing) elements should return Nullable(UInt8), not Nullable(Nothing).
2+
-- This previously caused a type mismatch assertion in MergingSortedAlgorithm when merging streams from GROUPING SETS.
3+
4+
SELECT or(equals(y, (NULL, '')), equals(x, x)), equals(y, materialize(toNullable((NULL, '')))), materialize((456, NULL))
5+
FROM system.one
6+
LEFT ARRAY JOIN [(NULL, ''), (123, 'Hello'), (456, NULL)] AS y, [1, NULL, 3] AS x
7+
WHERE or(equals(y, (NULL, '')), isNotDistinctFrom(x, x))
8+
GROUP BY GROUPING SETS ((y), (1))
9+
ORDER BY ALL DESC NULLS FIRST
10+
FORMAT Null;
11+
12+
-- Simpler cases for tuple comparison with Nothing type
13+
SELECT (1, 2) = (NULL, 2);
14+
SELECT (NULL, 'a') = (1, 'a');
15+
SELECT toTypeName((NULL, 'a') = (1, 'a'));

0 commit comments

Comments
 (0)