Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 841 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Representation of Set in java versus CQL

#1
I'm new in cassandra and I try to add to a table a set of data. My table looks like:

CREATE TABLE myTable (id int, name varchar, mySet set<uuid>, PRIMARY KEY (id));

The problem that I met is when I do my request the type are not compatible, the string representation of a set in Java is [uuid1,uuid2,...] and the representation in cql is {'uuid1','uuid2',...}

session.execute("INSERT INTO myTable (id , name, mySet) VALUES (" + myID + ", '" + myName +"' ," + mySet + ");");

So do you know guys if there is a function or a library which will directly fix this problem. Thanks a lot.
Reply

#2
Instead of appending the set contents to the query string (which uses the set .toString() implementation) you could instead do the following (cassandra 2.0+ required):

session.execute("INSERT INTO myTable (id, name, mySet) VALUES (?, ?, ?));", myId, myName, mySet);

The driver will then take care of injecting the Set properly for you. You could also consider using a [BoundStatement](

[To see links please register here]

) or [QueryBuilder](

[To see links please register here]

) to accomplish this as well.
Reply

#3
I would also recommend you to use prepared statements as well. Besides other reasons, C* does a bunch of work it will cache for any query if it's a p_stmnt, making those faster next time you issue them. Not using p_stmnts will make c* repeat that work over and over again instead of using the cache.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through