[
https://issues.apache.org/jira/browse/SPARK-57298?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Yang updated SPARK-57298:
------------------------------
Description:
`collect_set` is documented to return a set of distinct elements, and under
Spark SQL semantics all NaN values are equal (and `-0.0 == 0.0`). However,
`collect_set` over float/double columns returns duplicate `NaN` elements:
{code:java}
-- Top-level NaN: HashSet compares boxed values with primitive equality (NaN !=
NaN)
SELECT collect_set(v) FROM VALUES (double('NaN')), (double('NaN')) AS t(v);
-- before: [NaN, NaN] after: [NaN]
-- Nested -0.0 / 0.0: GenericArrayData/GenericInternalRow hash -0.0 and 0.0 to
-- different buckets, so they are not deduplicated
SELECT collect_set(a) FROM VALUES (array(-0.0D)), (array(0.0D)) AS t(a);
-- before: [[-0.0], [0.0]] after: [[0.0]]
SELECT collect_set(named_struct('a', v)) FROM VALUES (-0.0D), (0.0D) AS t(v);
-- before: [{a:-0.0}, {a:0.0}] after: [{a:0.0}]
{code}
This is inconsistent with array_distinct , count(DISTINCT),
grouping/join/window keys, and the array set operations - all of which treat
NaNs as equal.
was:
`collect_set` is documented to return a set of distinct elements, and under
Spark SQL semantics all NaN values are equal (and `-0.0 == 0.0`). However,
`collect_set` over float/double columns returns duplicate `NaN` elements:
{code:java}
SELECT collect_set(v) FROM VALUES (double('NaN')), (double('NaN')) AS t(v);
-- actual: [NaN, NaN]
-- expected: [NaN] {code}
This is inconsistent with array_distinct , count(DISTINCT),
grouping/join/window keys, and the array set operations - all of which treat
NaNs as equal.
> collect_set returns duplicate NaN values for float/double columns
> -----------------------------------------------------------------
>
> Key: SPARK-57298
> URL: https://issues.apache.org/jira/browse/SPARK-57298
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 5.0.0
> Reporter: Eric Yang
> Priority: Major
> Labels: pull-request-available
>
> `collect_set` is documented to return a set of distinct elements, and under
> Spark SQL semantics all NaN values are equal (and `-0.0 == 0.0`). However,
> `collect_set` over float/double columns returns duplicate `NaN` elements:
> {code:java}
> -- Top-level NaN: HashSet compares boxed values with primitive equality (NaN
> != NaN)
> SELECT collect_set(v) FROM VALUES (double('NaN')), (double('NaN')) AS t(v);
> -- before: [NaN, NaN] after: [NaN]
> -- Nested -0.0 / 0.0: GenericArrayData/GenericInternalRow hash -0.0 and 0.0 to
> -- different buckets, so they are not deduplicated
> SELECT collect_set(a) FROM VALUES (array(-0.0D)), (array(0.0D)) AS t(a);
> -- before: [[-0.0], [0.0]] after: [[0.0]]
> SELECT collect_set(named_struct('a', v)) FROM VALUES (-0.0D), (0.0D) AS t(v);
> -- before: [{a:-0.0}, {a:0.0}] after: [{a:0.0}]
> {code}
> This is inconsistent with array_distinct , count(DISTINCT),
> grouping/join/window keys, and the array set operations - all of which treat
> NaNs as equal.
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]