[ 
https://issues.apache.org/jira/browse/CALCITE-3021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16849090#comment-16849090
 ] 

Michael Mior commented on CALCITE-3021:
---------------------------------------

Fixed in 
[{{ab40586}}|https://github.com/apache/calcite/commit/ab40586dd6b6a8daff5054176db463d63e9c250c]

> Equality of nested ROWs returns false for identical values
> ----------------------------------------------------------
>
>                 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: 50m
>  Remaining Estimate: 0h
>
> Problem can be reproduced via:
> {code:sql}
> select distinct * from (values
>     (1, ROW(1,1)),
>     (1, ROW(1,1)),
>     (2, ROW(2,2))) as v(id,struct);
> {code}
> Which incorrectly returns a duplicated value:
> {code}
> +----+--------+
> | ID | STRUCT |
> +----+--------+
> |  1 | {1, 1} |
> |  1 | {1, 1} |
> |  2 | {2, 2} |
> +----+--------+
> (3 rows)
> {code}
> The root cause is that 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)

Reply via email to