You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Michael Mior (JIRA)" <ji...@apache.org> on 2019/05/27 17:16:00 UTC

[jira] [Resolved] (CALCITE-3021) Equality of nested ROWs returns false for identical values

     [ https://issues.apache.org/jira/browse/CALCITE-3021?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Mior resolved CALCITE-3021.
-----------------------------------
    Resolution: Fixed

> 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)