[
https://issues.apache.org/jira/browse/CALCITE-7952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149592#comment-18149592
]
Kirill Tkalenko commented on CALCITE-7952:
------------------------------------------
I verified both examples through Calcite JDBC before and after the change.
{code:java}
-- Before: FALSE. After: TRUE.
SELECT 1.00 MEMBER OF MULTISET[1.0];
-- With the Spark SQL library enabled. Before: 2. After: 1.
SELECT CARDINALITY(ARRAY_UNION(ARRAY[ARRAY[1.0]], ARRAY[ARRAY[1.00]]));
{code}
My assumption is that collection operations should use the same numeric
equality as SQL {{{}={}}}. Since {{1.0}} and {{1.00}} compare equal, they
should also hash alike when removing duplicates. I propose fixing comparison
and hashing together so these operations work consistently while preserving the
original decimal values.
I also ran equivalent queries in
[Oracle|https://onecompiler.com/oracle/459zua3qz] and
[PostgreSQL|https://onecompiler.com/postgresql/459zua3gz]. Both found a match
and counted one distinct value. PostgreSQL did so while retaining scales of
{{1}} and {{{}2{}}}.
I tested Apache Spark SQL 3.5.8 locally. {{ARRAY_CONTAINS}} returned {{TRUE}}
after Spark implicitly aligned the decimal types. The nested {{ARRAY_UNION}}
returned one element after an explicit cast to a common decimal type.
> Functions.deepEquals and Functions.deepHashCode should ignore BigDecimal scale
> ------------------------------------------------------------------------------
>
> Key: CALCITE-7952
> URL: https://issues.apache.org/jira/browse/CALCITE-7952
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.42.0
> Reporter: Kirill Tkalenko
> Assignee: Kirill Tkalenko
> Priority: Major
> Labels: pull-request-available
>
> {{Functions.deepEquals}} treats numerically equal {{BigDecimal}} values such
> as {{1.0}} and {{1.00}} as different, and {{Functions.deepHashCode}} can
> assign them different hashes. Deep equality should compare decimal values
> numerically and produce identical hashes for equal values, including when
> they appear inside arrays, lists, or maps.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)