sepuri sai krishna created SPARK-62382:
------------------------------------------
Summary: GROUP BY on a map splits maps whose keys are 0.0 and -0.0
Key: SPARK-62382
URL: https://issues.apache.org/jira/browse/SPARK-62382
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 4.0.0
Reporter: sepuri sai krishna
GROUP BY and DISTINCT on a map put two maps that differ only in a 0.0 or -0.0
key into different groups, when the map was built by map(), map_from_arrays or
transform_keys.
{code:sql}
CREATE OR REPLACE TEMP VIEW t AS
SELECT -CAST(id AS DOUBLE) AS x FROM range(1) -- -0.0
UNION ALL
SELECT CAST(id AS DOUBLE) FROM range(1); -- 0.0
SELECT m, count(*) FROM (SELECT map(x, 1) AS m FROM t) GROUP BY m;
-- {-0.0:1} 1
-- {0.0:1} 1
-- expected: {0.0:1} 2
SELECT count(DISTINCT m) FROM (SELECT map(x, 1) AS m FROM t);
-- 2, expected 1
{code}
The same happens for map_from_arrays(array(x), array(1)) and
transform_keys(map(1, 1), (k, v) -> x). A GROUP BY on x itself returns one
group.
SPARK-47563 normalizes FLOAT and DOUBLE keys when ArrayBasedMapBuilder builds a
map (-0.0 to 0.0, and every NaN to one NaN), so that GROUP BY on a map
(SPARK-47430) treats such keys as one key; NormalizeFloatingNumbers normalizes
only the values of a map and relies on it. ArrayBasedMapBuilder.from normalizes
the keys to detect duplicates, but when there is none it returns the input key
array, so the keys are not normalized. map_from_arrays and transform_keys build
their maps with from, and so does the generated code of map(). The interpreted
map() builds its map with put and build, so map() returns one group only when
the codegen factory mode is NO_CODEGEN.
Reproduced on 4.0.3 and on master.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]