[
https://issues.apache.org/jira/browse/FLINK-40945?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18151077#comment-18151077
]
Martijn Visser commented on FLINK-40945:
----------------------------------------
NaN goes the other way. A hash join matches NaN to NaN because the bytes are
equal, while sort-merge and nested-loop joins never match it. So SELECT k FROM
l INTERSECT SELECT k FROM r with NaN on both sides returns NaN with a hash join
and drops it with a sort-merge join; EXCEPT does the reverse.
> -0.0 and 0.0 are different keys in GROUP BY, DISTINCT, UNION and hash joins
> ---------------------------------------------------------------------------
>
> Key: FLINK-40945
> URL: https://issues.apache.org/jira/browse/FLINK-40945
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Runtime
> Affects Versions: 2.3.0, 2.4.0
> Reporter: Yaoxuan Wu
> Priority: Major
>
> {code:java}
> CREATE TEMPORARY VIEW v AS SELECT CAST(s AS DOUBLE) AS x FROM (VALUES
> ('-0.0'), ('0.0')) AS t(s);
> SELECT a.x, b.x, a.x = b.x FROM v a, v b; -- TRUE for all four pairs
> SELECT DISTINCT x FROM v; -- Flink: -0.0, 0.0
> expected: one row
> SELECT COUNT(DISTINCT x) FROM v; -- Flink: 2
> expected: 1
> SELECT x, COUNT(*) FROM v GROUP BY x; -- Flink: (-0.0, 1), (0.0, 1)
> expected: one group with count 2
> SELECT x FROM v UNION SELECT x FROM v; -- Flink: 2 rows
> expected: 1 rowSET 'table.exec.disabled-operators' =
> 'SortMergeJoin,NestedLoopJoin';
> SELECT a.x, b.x FROM v a JOIN v b ON a.x = b.x;
> -- HashJoin: (-0.0, -0.0), (0.0, 0.0) expected: all 4 pairs
> (SortMergeJoin / NestedLoopJoin return 4) {code}
> The comparison -0.0 = 0.0 is TRUE, but grouping, deduplication and hash join
> keys treat the two zeros as different values, so the result depends on the
> operator (and, for joins, on the join algorithm). IN (subquery) and INTERSECT
> treat them as equal. FLOAT behaves the same. Streaming mode behaves the same
> for DISTINCT, GROUP BY and JOIN.
> (The CAST over a string column is only there to produce -0.0: a literal -0.0
> or CAST('-0.0' AS DOUBLE) is constant-folded to 0.0.)
> Also reproduces on current master (2.4-SNAPSHOT, a47e4bf).
> Related: FLINK-40693 (same problem for constant IN lists, fixed in 2.4.0)
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)