[prev in list] [next in list] [prev in thread] [next in thread] 

List:       avro-user
Subject:    Re: Custom hashCode function
From:       Doug Cutting <cutting () apache ! org>
Date:       2014-05-28 17:28:34
Message-ID: CALEq1Z8_XmHCpCu7=rv_epBSHo4k+JE8860zHFrzS6xWJxBZ+A () mail ! gmail ! com
[Download RAW message or body]

On Mon, May 26, 2014 at 3:43 AM, Han JU <ju.han.felix@gmail.com> wrote:
> My question for the moment: is it possible to custom the hashCode function
> of a avro record? Say a record a a field `uid` and I'd like to return this
> value as the hashCode.

If you're using Avro's reflect model then you can simply override your
hashCode method.

If you're using generic or specific then you can specify a schema
where all other fields are ignored, e.g.:

{"type":"record", "name":"org.random.Foo", "fields":[
  {"name":"uid", "type":"string"},
  {"name":"x", "type":"long", "order":"ignore"},
  {"name":"y", "type":"float", "order":"ignore"},
  {"name":"z", "type":"double", "order":"ignore"}
]}

Avro's hashes and comparisons only consider fields that are not ignored.

Doug
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic