"EXISTS" Clause in java driver

22 views
Skip to first unread message

Matthieu Baechler

unread,
Jul 17, 2015, 12:26:32 PM7/17/15
to java-dri...@lists.datastax.com
Hi,

I'm trying to write some code that make sure my UPDATE statement won't create a new row if it doesn't exist.

I tried in plain CQL :

$ CREATE TABLE users ( name text, description text, PRIMARY KEY (name) );
$ INSERT INTO users (name, description) VALUES ( 'bob', 'great guy');
$ UPDATE users SET description = 'another description' WHERE name = 'bob' IF EXISTS;

 [applied]
-----------
      True


$ UPDATE users SET description = 'another description' WHERE name = 'alice' IF EXISTS;

 [applied]
-----------
     False

It looks like it's what I want.

I tried to write it with the java driver but I can't find an "exists" Clause to give to Update.onlyIf method.

I use 2.1.5 driver but I also checked in 2.1.7 and 2.2. Is there something I'm missing or I just need to contribute this clause to the java driver ?

Thanks for your answers.

--
Matthieu Baechler

Olivier Michallat

unread,
Jul 17, 2015, 12:41:22 PM7/17/15
to java-dri...@lists.datastax.com
Hi,

You're running into JAVA-827. The UPDATE... IF EXISTS syntax is not yet supported by the query builder.

--

Olivier Michallat

Driver & tools engineer, DataStax


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Matthieu Baechler

unread,
Jul 21, 2015, 4:00:34 PM7/21/15
to java-dri...@lists.datastax.com
Hi Olivier,

Thanks for your reply. I have done a PR for this (before realizing there's already one attached to the JIRA).
Do you plan to merge one soon ?

-- 
Matthieu Baechler

Alexandre Dutra

unread,
Jul 22, 2015, 5:53:10 AM7/22/15
to java-dri...@lists.datastax.com
Hi Matthieu,

Indeed, there was already a PR open for this ticket, and we are going to merge that one (on a side note, we require our PRs to be made against 2.0 branch whenever applicable). Your remarks regarding the validity of the resulting statement are nonetheless perfectly valid.

There is currently no timeframe for this ticket, but given that it's trivial, we might consider including it in the forthcoming 2.0.11 release.

If you are missing this feature, please vote for it on Jira: https://datastax-oss.atlassian.net/browse/JAVA-827.

Thanks,

Alexandre
--
Alexandre Dutra
Driver & Tools Engineer @ DataStax

Matthieu Baechler

unread,
Jul 24, 2015, 8:09:07 AM7/24/15
to java-dri...@lists.datastax.com
Hi,

I just updated my PR and created another one for 2.0 branch with some care about not being able to chain any method call after ifExists.

Maybe Ranger Tsao will update its PR too but if it doesn't happen, you still have mine.

Thanks,

--
Matthieu Baechler
Reply all
Reply to author
Forward
0 new messages