You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Ali Akhtar <al...@gmail.com> on 2016/11/07 12:14:31 UTC

Using a Set for UDTs, how is uniqueness established?

I have a UDT which contains a text 'id' field, which should be used to
establish the uniqueness of the UDT.

I'd like to have a set<my_udt> field in a table, and I'd like to use the id
of the udts to establish uniqueness.

Any ideas how this can be done? Also using Java, and c* 3.7

Re: Using a Set for UDTs, how is uniqueness established?

Posted by Ali Akhtar <al...@gmail.com>.
Huh, so that means updates to the udt values won't be possible?

Sticking to a map<string, udt> then.

On Mon, Nov 7, 2016 at 5:31 PM, DuyHai Doan <do...@gmail.com> wrote:

> So, to compare UDT values, Cassandra will compare them field by field. So
> that udt1.equals(udt2) results in:
>
>       udt1.field1.equals(udt2.field1)
> && udt1.field2.equals(udt2.field2)
> ...
> && udt1.fieldN.equals(udt2.fieldN)
>
> Your idea of using field "id" to distinguish between UDT value is good
> e.g. if the "id" value mismatches then the 2 UDT are different. However, if
> the "id" values do match, it does not guarantee that the UDT values match
> since it requires that all other fields match.
>
>
>
> On Mon, Nov 7, 2016 at 1:14 PM, Ali Akhtar <al...@gmail.com> wrote:
>
>> I have a UDT which contains a text 'id' field, which should be used to
>> establish the uniqueness of the UDT.
>>
>> I'd like to have a set<my_udt> field in a table, and I'd like to use the
>> id of the udts to establish uniqueness.
>>
>> Any ideas how this can be done? Also using Java, and c* 3.7
>>
>
>

Re: Using a Set for UDTs, how is uniqueness established?

Posted by DuyHai Doan <do...@gmail.com>.
So, to compare UDT values, Cassandra will compare them field by field. So
that udt1.equals(udt2) results in:

      udt1.field1.equals(udt2.field1)
&& udt1.field2.equals(udt2.field2)
...
&& udt1.fieldN.equals(udt2.fieldN)

Your idea of using field "id" to distinguish between UDT value is good e.g.
if the "id" value mismatches then the 2 UDT are different. However, if the
"id" values do match, it does not guarantee that the UDT values match since
it requires that all other fields match.



On Mon, Nov 7, 2016 at 1:14 PM, Ali Akhtar <al...@gmail.com> wrote:

> I have a UDT which contains a text 'id' field, which should be used to
> establish the uniqueness of the UDT.
>
> I'd like to have a set<my_udt> field in a table, and I'd like to use the
> id of the udts to establish uniqueness.
>
> Any ideas how this can be done? Also using Java, and c* 3.7
>