kafka-jira mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tobias Gies (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (KAFKA-6308) Connect: Struct equals/hashCode method should use Arrays#deep* methods
Date Mon, 04 Dec 2017 17:30:00 GMT

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

Tobias Gies updated KAFKA-6308:
-------------------------------
    Description: 
At the moment, {{org.apache.kafka.connect.data.Struct#equals}} checks two things, after ensuring
the incoming {{Object o}} is indeed of the correct type:

* Whether the schemas of {{this}} and {{o}} are equal, via {{Objects#equals}}
* Whether the values of {{this}} and {{o}} are qual, via {{Arrays#equals}}.

The latter check is problematic. {{Arrays#equals}} is meant for one-dimensional arrays of
any kind, and thus simply checks the {{equals}} methods of all corresponding elements of its
parameters {{a1}} and {{a2}}. However, elements of the {{Struct#values}} array may themselves
be arrays in a specific case, namely if a field has a {{BYTES}} Schema Type and the user's
input for this field is of type {{byte[]}}.

Given that, I would suggest to use {{Arrays#deepEquals}} to compare the {{values}} arrays
of two {{Struct}} instances. With similar reasoning, I would also suggest to use {{Arrays#deepHashCode}}
in the Struct's {{hashCode}} method.

This would allow to properly compare and hash structs that get byte arrays passed in as field
values instead of the recommended ByteBuffers.

  was:
At the moment, {{org.apache.kafka.connect.data.Struct#equals}} checks two things, after ensuring
the incoming {{Object o}} is indeed of the correct type:

* Whether the schemas of {{this}} and {{o}} are equal, via {{Objects#equals}}
* Whether the values of {{this}} and {{o}} are qual, via {{Arrays#equals}}.

The latter check is problematic. {{Arrays#equals}} is meant for one-dimensional arrays of
any kind, and thus simply checks the {{equals}} methods of all corresponding elements of its
parameters {{a1}} and {{a2}}. However, elements of the {{Struct#values}} array may themselves
be arrays in a specific case, namely if a field has a {{BYTES}} Schema Type and the user's
input for this field is of type {{byte[]}}.

Given that, I would suggest to use {{Arrays#deepEquals}} to compare the {{values}} arrays
of two {{Struct}} instances. With similar reasoning, I would also suggest to use {{Arrays#deepHashCode}}
in a Struct's {{hashCode}} method.

This would allow to properly compare and hash structs that get byte arrays passed in as field
values instead of the recommended ByteBuffers.


> Connect: Struct equals/hashCode method should use Arrays#deep* methods
> ----------------------------------------------------------------------
>
>                 Key: KAFKA-6308
>                 URL: https://issues.apache.org/jira/browse/KAFKA-6308
>             Project: Kafka
>          Issue Type: Bug
>          Components: KafkaConnect
>    Affects Versions: 1.0.0
>            Reporter: Tobias Gies
>              Labels: easyfix, newbie
>
> At the moment, {{org.apache.kafka.connect.data.Struct#equals}} checks two things, after
ensuring the incoming {{Object o}} is indeed of the correct type:
> * Whether the schemas of {{this}} and {{o}} are equal, via {{Objects#equals}}
> * Whether the values of {{this}} and {{o}} are qual, via {{Arrays#equals}}.
> The latter check is problematic. {{Arrays#equals}} is meant for one-dimensional arrays
of any kind, and thus simply checks the {{equals}} methods of all corresponding elements of
its parameters {{a1}} and {{a2}}. However, elements of the {{Struct#values}} array may themselves
be arrays in a specific case, namely if a field has a {{BYTES}} Schema Type and the user's
input for this field is of type {{byte[]}}.
> Given that, I would suggest to use {{Arrays#deepEquals}} to compare the {{values}} arrays
of two {{Struct}} instances. With similar reasoning, I would also suggest to use {{Arrays#deepHashCode}}
in the Struct's {{hashCode}} method.
> This would allow to properly compare and hash structs that get byte arrays passed in
as field values instead of the recommended ByteBuffers.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message