Java Driver for Cassandra - exclude null values in delete query using mapper

214 views
Skip to first unread message

Mcm

unread,
Jun 30, 2016, 6:53:58 AM6/30/16
to DataStax Java Driver for Apache Cassandra User Mailing List
I am trying to do a delete by a primary key using the mapper -> mapper.deleteQuery(new FooModel(fid)); , but I encountered an error. Looking at the delete query the mapper constructed I noticed even null fields from the FooModel where included. Is there a way I can exclude the null values from the query ?

Note: Mapper.Option.saveNullFields(...) wont work on a delete query.

Andrew Tolbert

unread,
Jun 30, 2016, 10:06:40 AM6/30/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Mcm,

Mapper.Option.saveNullFields(...) does not apply for deletes because it deletes the entire row, so the contents over your fields other than the primary keys are not relevant or used.  Therefore there is no need to worry about non-primary key column values being null when performing a delete using the mapper.

Thanks,
Andy

Mcm

unread,
Jul 4, 2016, 4:53:37 AM7/4/16
to DataStax Java Driver for Apache Cassandra User Mailing List
So my primary key looks like this: PRIMARY KEY ((fooid), timestamp, id)) -> Can I use  mapper.deleteQuery to only remove by fooid ?

Regards,
Marjan

Andrew Tolbert

unread,
Jul 4, 2016, 11:01:23 AM7/4/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Marjan,

This is not supported at this time.  Mapper.delete|deleteQuery requires the full primary key to be specified.  One option is to use an Accessor to specify a delete by partition, i.e.:

@Accessor
public interface BarAccessor {
    @Query("DELETE FROM bar WHERE fooid=?")
    ResultSet deleteByFoo(UUID fooId);
}

Thanks,
Andy

Marjan Tanevski

unread,
Jul 6, 2016, 9:16:05 AM7/6/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Thanks for support and answer. I am using accessor for the time being. Wish to see excluding null fields from query supported in the next version.

Kind regards,
Marjan
Reply all
Reply to author
Forward
0 new messages