NullSavingstragy DO NOT SET dosent work

155 views
Skip to first unread message

Amol Khanolkar

unread,
Sep 4, 2020, 8:22:00 AM9/4/20
to DataStax Java Driver for Apache Cassandra User Mailing List
I see mappper code generated checks for each and every fields in UDT
if NULL saving strategy is DO_NOT_SET to null and if udt fileds value is null. It dosent set the value.. 

However Since it created new UdtValue() it accidentally ends up setting all null fields to null

Eg
I have UDT with below defination
UDT (a text,b text)
Table( col1 UDT ..... )

When Null saving strategy is DO_NOT _SET TO null ideally query should be generated like
update table set col1.a = 'aValue' if b is null
else
update table set col1.b = 'bvalue' if a is null
else
update table set col1.a = 'aValue', col1.b = 'bvalue' if b is nothing is null

However currently it ends up having 
update table set col1=udtValue({})

Now if my table  col1 status is 
col1 = {a:"value1",b:"Value2"}
in such case if I update UDT with only value b.. it gets overwritten

Regards
Amol




Olivier Michallat

unread,
Sep 8, 2020, 1:09:32 PM9/8/20
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

The null saving strategy only applies to top-level columns, not nested fields. In other words, UDTs are "all or nothing": if you pass an entity with null values, the corresponding fields will indeed be overwritten, that is expected behavior.

The mapper generates a request that sets the UDT column as a whole, as in "SET col1 = ?". 
The syntax "SET col1.a = ? , col1.b = ?" that you mentioned only works with Cassandra 3.6 and above. Even then it only works for non-frozen UDTs. As a consequence, it does not generalize to nested UDTs or UDTs inside collections ("col1.a.b"or "col1[0].a"are not valid syntaxes). So even though it is technically feasible to support it, it would be cumbersome: we'd have to add runtime checks for the Cassandra version and "frozenness" of the column, and switch to a different query dynamically.

I would also look at this from a data modelling perspective: if you have a value that gets updated independently, then maybe it shouldn't be grouped with other fields inside of a UDT.

Olivier Michallat



--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
To view this discussion on the web visit https://groups.google.com/a/lists.datastax.com/d/msgid/java-driver-user/bc2d8210-2302-43c9-a392-0c867b4aa170n%40lists.datastax.com.
Reply all
Reply to author
Forward
0 new messages