-
Notifications
You must be signed in to change notification settings - Fork 31
Using CQL
You are expected to know what you are getting into if you plan on using CQL queries in your application. Spend some time looking through the unit tests here in Hector and the Cassandra source tree. For a number of detailed examples, see test_cql.py in the test/system folder of the Apache Cassandra source distribution.
Note: if you immediately get an exception such as: "InvalidRequestException(why:cannot parse 'foo' as hex bytes)" It means one of two things:
- You have not formatted your query correctly
- You have not configured the correct validators (any combination of key, comparator, default, and column metadata) on your column family
In both cases, even though the query is most likely a string, it is up to you to format this query according to the column family configuration. This can be a little confusing as only the comparator is required when defining a column family which itself will default to BytesType.
To set a column with named "birthyear" to the value "1976" (treating these as a String and a long respectively) we would have following update statement:
update StandardLong1 set 'birthyear' = '1976' WHERE KEY = 'mykey1'
We can pass this statement as a String to CqlQuery#setQuery if the Following conditions are true on the column family StandardLong1:
- Comparator is UTF8Type
- Key validator is UTF8Type
- We have column metadata which defines the column "birthyear" accepts values of LongType
To insert the same values as a single CQL String into another column family with no additional configuration options, you are responsible for the bytes (hexadecimal) conversion yourself:
update Standard1 set '626972746879656172' = '31393736' WHERE KEY = '6d796b657931'
https://github.com/rantav/hector/blob/master/core/src/test/java/me/prettyprint/cassandra/model/CqlQueryTest.java http://www.datastax.com/docs/0.8/api/using_cql http://www.datastax.com/docs/0.8/api/cql_ref