[
https://issues.apache.org/jira/browse/CALCITE-3021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16844785#comment-16844785
]
Ruben Quesada Lopez commented on CALCITE-3021:
----------------------------------------------
I found this (which I think confirms that the expected behavior is the new
test):
{quote}*distinct*: Two values other than rows and collections are said to be
not distinct if either: both
are the null value, or they compare equal according to Subclause 8.2,
‘‘<comparison predicate>’’;
otherwise they are distinct. Two rows (or partial rows) are distinct if at
least one of their pairs
of respective values is distinct; otherwise they are not distinct. Two arrays
are distinct if the
arrays do not have the same cardinality or if, for arrays of the same
cardinality, elements in
the same ordinal position in the two arrays are distinct; otherwise, the
arrays are not distinct.
The result of evaluating whether or not two values, two rows, or two arrays
are distinct is never
unknown.
...
*8.2 <comparison predicate>*
...
iv) If the declared types of Xi and Yi are row types, then let RV1 and RV2 be
<value
expression>s whose declared types are respectively that of Xi and Yi. The
Syntax Rules
of this Subclause are applied to:
RV1 <comp op> RV2
{quote}
> ArrayEqualityComparer should use Arrays#deepEquals/deepHashCode instead of
> Arrays#equals/hashCode
> -------------------------------------------------------------------------------------------------
>
> Key: CALCITE-3021
> URL: https://issues.apache.org/jira/browse/CALCITE-3021
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.19.0
> Reporter: Ruben Quesada Lopez
> Assignee: Ruben Quesada Lopez
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.20.0
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> Currently, ArrayEqualityComparer (which is used as comparer for
> JavaRowFormat.ARRAY) performs the array comparison based on Arrays#equals and
> Arrays#hashCode (see Functions.java):
> {code:java}
> private static class ArrayEqualityComparer implements
> EqualityComparer<Object[]> {
> public boolean equal(Object[] v1, Object[] v2) {
> return Arrays.equals(v1, v2);
> }
> public int hashCode(Object[] t) {
> return Arrays.hashCode(t);
> }
> }
> {code}
> This will lead to incorrect comparisons in case of multidimensional arrays,
> e.g. a row (array) with a struct field (another array) inside. To fix the
> issue, Arrays#deepEquals / Arrays#deepHashCode should be used:
> {code:java}
> private static class ArrayEqualityComparer implements
> EqualityComparer<Object[]> {
> public boolean equal(Object[] v1, Object[] v2) {
> return Arrays.deepEquals(v1, v2);
> }
> public int hashCode(Object[] t) {
> return Arrays.deepHashCode(t);
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)