From 6231fb55f8fcc06c748b8f70fcf5976ed84010c0 Mon Sep 17 00:00:00 2001 From: Groene AI <270696204+groeneai@users.noreply.github.com> Date: Sun, 29 Nov 2026 13:55:16 +0000 Subject: [PATCH] fix(clickhouse): TLPDistinct and TLPSetOp treat -0 and 0 as the same value Since ClickHouse #130054, DISTINCT (and UNION DISTINCT, which is a DISTINCT over the union) treats -0. and 0. as one key and keeps the first row it sees, so which of the two zeros a query prints depends on row order. TLPDistinct and the UNION DISTINCT and INTERSECT checks of TLPSetOp compared the printed values as strings, so the same set of values printed as {0} on one side and {-0} on the other was reported as a mismatch. Map -0 to 0 with ComparatorHelper.canonicalizeResultValue before these set comparisons, as the DuckDB, Databend and Doris DISTINCT testers already do. INTERSECT ALL and EXCEPT ALL still compare the zeros bitwise on master, so a mismatch caused by that is still reported. Co-Authored-By: Claude Opus 5.5 --- .../oracle/tlp/ClickHouseTLPDistinctOracle.java | 2 +- .../oracle/tlp/ClickHouseTLPSetOpOracle.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPDistinctOracle.java b/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPDistinctOracle.java index 2d2426073..12fa35956 100644 --- a/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPDistinctOracle.java +++ b/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPDistinctOracle.java @@ -41,7 +41,7 @@ public void check() throws SQLException { } ComparatorHelper.assumeResultSetsAreEqual(resultSet, secondResultSet, originalQueryString, combinedString, - state); + state, ComparatorHelper::canonicalizeResultValue); } } diff --git a/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPSetOpOracle.java b/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPSetOpOracle.java index 2fc7d8f9e..2b4e319a9 100644 --- a/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPSetOpOracle.java +++ b/src/sqlancer/clickhouse/oracle/tlp/ClickHouseTLPSetOpOracle.java @@ -103,13 +103,21 @@ private void checkUnionDistinct() throws SQLException { throw new IgnoreMeException(); } - Set baselineSet = new HashSet<>(baselineRows); - Set branchSet = new HashSet<>(branchRows); + Set baselineSet = toSetIgnoringZeroSign(baselineRows); + Set branchSet = toSetIgnoringZeroSign(branchRows); if (!baselineSet.equals(branchSet)) { throw new AssertionError(formatFailure("UNION_DISTINCT", baseline, branchUnion, baselineRows, branchRows)); } } + private static Set toSetIgnoringZeroSign(List rows) { + Set set = new HashSet<>(); + for (String r : rows) { + set.add(ComparatorHelper.canonicalizeResultValue(r)); + } + return set; + } + private static boolean containsNanOrInfinity(List rows) { for (String r : rows) { if (r == null) { @@ -139,8 +147,8 @@ private void checkIntersect() throws SQLException { if (containsNanOrInfinity(branchRows) || containsNanOrInfinity(intersectRows)) { throw new IgnoreMeException(); } - Set intersectSet = new HashSet<>(intersectRows); - Set branchSet = new HashSet<>(branchRows); + Set intersectSet = toSetIgnoringZeroSign(intersectRows); + Set branchSet = toSetIgnoringZeroSign(branchRows); if (!intersectSet.equals(branchSet)) { throw new AssertionError( "INTERSECT subset violated: branch=" + branchName + " INTERSECT T produced " + intersectRows