You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Jacob Rhoden <ja...@me.com> on 2014/02/10 23:50:14 UTC

Using "IN" with the Datastax driver (2.0-??)

Hi Guys,

Im experimenting with using IN to reduce the number of quires I have to execute. The following works in CQL:

	i.e select log_entry from log_index where keyword in (‘keyword1’, ‘keyword2’, ‘keyword3’, etc…);

So I now want to work out how to convert this:

	PreparedStatement p = session.prepare("select log_entry from log_index where keyword=?”);
	session.execute(p.bind(keyword.toLowerCase())

To take a variable number of inputs, something like this???

	PreparedStatement p = session.prepare("select log_entry from log_index where keyword in (...)");
	session.execute(p.bind(….))

Thanks,
Jacob

Re: Using "IN" with the Datastax driver (2.0-??)

Posted by DuyHai Doan <do...@gmail.com>.
I don't know if it's documented somewhere. Personnally I got the info by
following the Cassandra dev blog and reading each new release notes.

 In each Cassandra release notes, you have a list of bug fixes but also new
features. Just read the corresponding JIRA to get the details.

 Regards

 Duy Hai DOAN


On Tue, Feb 11, 2014 at 12:18 AM, Jacob Rhoden <ja...@me.com> wrote:

> Perfect, thanks! I wonder if this is documented anywhere? Certainly I have
> no idea how to search google using the keyword "in" :D
>
>     String[] words = TagsToArray.tagsToArray(keyword.toLowerCase());
>     PreparedStatement p = api.getCassandraSession().prepare("select
> log_entry from log_index where keyword in ?");
>     session.execute(p.bind(Arrays.asList(words))));
>
> Thanks,
> Jacob
>
> On 11 Feb 2014, at 9:55 am, DuyHai Doan <do...@gmail.com> wrote:
>
> Hello Jacob,
>
>  You can try the bind marker for variadic param (new feature):
>
> PreparedStatement p = session.prepare("select log_entry from log_index
> where keyword *IN* ?");
>  session.execute(p.bind(Arrays.asList("keyword1","keyword2",...));
>
> Regards
>
>  Duy Hai DOAN
>
>
>

Re: Using "IN" with the Datastax driver (2.0-??)

Posted by Jacob Rhoden <ja...@me.com>.
Perfect, thanks! I wonder if this is documented anywhere? Certainly I have no idea how to search google using the keyword “in” :D

    String[] words = TagsToArray.tagsToArray(keyword.toLowerCase());
    PreparedStatement p = api.getCassandraSession().prepare("select log_entry from log_index where keyword in ?");
    session.execute(p.bind(Arrays.asList(words))));

Thanks,
Jacob

On 11 Feb 2014, at 9:55 am, DuyHai Doan <do...@gmail.com> wrote:

> Hello Jacob,
> 
>  You can try the bind marker for variadic param (new feature):
> 
> PreparedStatement p = session.prepare("select log_entry from log_index where keyword IN ?”);
> 	session.execute(p.bind(Arrays.asList("keyword1","keyword2",...));
> 
> Regards
> 
>  Duy Hai DOAN
> 


Re: Using "IN" with the Datastax driver (2.0-??)

Posted by DuyHai Doan <do...@gmail.com>.
Hello Jacob,

 You can try the bind marker for variadic param (new feature):

PreparedStatement p = session.prepare("select log_entry from log_index
where keyword *IN* ?");
session.execute(p.bind(Arrays.asList("keyword1","keyword2",...));

Regards

 Duy Hai DOAN


On Mon, Feb 10, 2014 at 11:50 PM, Jacob Rhoden <ja...@me.com> wrote:

> Hi Guys,
>
> Im experimenting with using IN to reduce the number of quires I have to
> execute. The following works in CQL:
>
> i.e select log_entry from log_index where keyword in ('keyword1',
> 'keyword2', 'keyword3', etc...);
>
> So I now want to work out how to convert this:
>
> PreparedStatement p = session.prepare("select log_entry from log_index
> where keyword=?");
> session.execute(p.bind(keyword.toLowerCase())
>
> To take a variable number of inputs, something like this???
>
> PreparedStatement p = session.prepare("select log_entry from log_index
> where keyword in (...)");
> session.execute(p.bind(....))
>
> Thanks,
> Jacob
>