[ https://issues.apache.org/jira/browse/IGNITE-4011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15572132#comment-15572132 ]
Alexander Paschenko commented on IGNITE-4011: --------------------------------------------- After consulting few guys who are Committers, I have made few changes to the API according to their notes. First, the interface to hash and compare objects is now named {{BinaryTypeIdentity}}, and it looks as follows: {code:java} /** * Method to compute hash codes for new binary objects and compare them for equality. */ public interface BinaryTypeIdentity { /** * @param obj Binary object builder. * @return Hash code value. */ public int hash(BinaryObject obj); /** * Compare binary objects for equality in consistence with how hash code is computed. * * @param o1 First object. * @param o2 Second object. * @return */ public boolean equals(BinaryObject o1, BinaryObject o2); } {code} Second, {{BinaryTypeIdentity}} is now part not to {{CacheKeyConfiguration}}, but rather to {{BinaryTypeConfiguration}} - it makes sense as some objects may be part of other objects, moreover, concepts of equality and hashing make sense not only for keys. Third, there are two default implementations a user could utilize - namely, {{FullIdentity}} and {{FieldsListIdentity}}. {{FullIdentity}} should be used when the objects compared definitely have the same binary schema, and it hashes/compares objects based on their fields list (sorted by id). And {{FieldsListIdentity}} considers not all fields but only those listed by user in configuration, in user specified order. If the user has not specified identity in configuration, current mechanism (explicit set hash code/byte array based one) will be used. Configuration example: {code:xml} <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" parent="base-ignite.cfg"> <!-- other properties --> <property name="marshaller"> <bean class="org.apache.ignite.internal.binary.BinaryMarshaller"/> </property> <property name="cacheKeyConfiguration"> <list> <bean class="org.apache.ignite.cache.CacheKeyConfiguration"> <property name="typeName" value="BinaryKeyWithLegacyIdentity"/> <property name="affinityKeyFieldName" value="f3" /> </bean> <bean class="org.apache.ignite.cache.CacheKeyConfiguration"> <property name="typeName" value="BinaryKeyWithFullIdentity"/> <property name="affinityKeyFieldName" value="f3" /> </bean> <bean class="org.apache.ignite.cache.CacheKeyConfiguration"> <property name="typeName" value="BinaryKeyWithFieldsListIdentity"/> <property name="affinityKeyFieldName" value="field3" /> </bean> </list> </property> <property name="binaryConfiguration"> <bean class="org.apache.ignite.configuration.BinaryConfiguration"> <property name="typeConfigurations"> <list> <bean class="org.apache.ignite.binary.BinaryTypeConfiguration"> <property name="typeName" value="BinaryKeyWithLegacyIdentity"/> <!-- no identity - manual hashing, byte array based comparison --> </bean> <bean class="org.apache.ignite.binary.BinaryTypeConfiguration"> <property name="typeName" value="BinaryKeyWithFullIdentity"/> <property name="identity"> <bean class="org.apache.ignite.internal.binary.FullIdentity"/> </property> </bean> <bean class="org.apache.ignite.binary.BinaryTypeConfiguration"> <property name="typeName" value="BinaryKeyWithFieldsListIdentity"/> <property name="identity"> <bean class="org.apache.ignite.internal.binary.FieldsListIdentity"> <property name="fieldsList"> <list> <value>field1</value> <value>field3</value> </list> </property> </bean> </property> </bean> </list> </property> </bean> </property> <!-- more properties --> {code} > Automatically compute hash codes for newly built binary objects > --------------------------------------------------------------- > > Key: IGNITE-4011 > URL: https://issues.apache.org/jira/browse/IGNITE-4011 > Project: Ignite > Issue Type: Task > Components: binary, cache > Reporter: Alexander Paschenko > Assignee: Alexander Paschenko > Fix For: 1.8 > > > For binary keys built automatically inside SQL engine during INSERT or MERGE, > we need to compute hash codes automatically because in this case the user > does not interact with any builders and can't set hash code explicitly. -- This message was sent by Atlassian JIRA (v6.3.4#6332)