Question

I have recently started taking much interest in CQL as I am thinking to use Datastax Java driver. Previously, I was using column family instead of table and I was using Astyanax driver. I need to clarify something here-

I am using the below column family definition in my production cluster. And I can insert any arbitrary columns (with its value) on the fly without actually modifying the column family schema.

create column family FAMILY_DATA
with key_validation_class = 'UTF8Type'
and comparator = 'UTF8Type'
and default_validation_class = 'BytesType'
and gc_grace = 86400;

But after going through this post, it looks like- I need to alter the schema every time whenever I am getting a new column to insert which is not what I want to do... As I believe CQL3 requires column metadata to exist...

Is there any other way, I can still add arbitrary columns and its particular value if I am going with Datastax Java driver?

Any code samples/example will help me to understand better.. Thanks..

Était-ce utile?

La solution

I believe in CQL you solve this problem using collections.

You can define the data type of a field to be a map, and then insert arbitrary numbers of key-value pairs into the map, that should mostly behave as dynamic columns did in traditional Thrift.

Something like:

CREATE TABLE data ( data_id int PRIMARY KEY, data_time long, data_values map );
INSERT INTO data (data_id, data_time, data_values) VALUES (1, 21341324, {'sum': 2134, 'avg': 44.5 });

Here is more information.

Additionally, you can find the mapping between the CQL3 types and the Java types used by the DataStax driver here.

Autres conseils

If you enable compact storage for that table, it will be backwards compatible with thrift and CQL 2.0 both of which allow you to enter dynamic column names.

You can have as many columns of whatever name you want with this approach. The primary key is composed of two things, the first element which is the row_key and the remaining elements which when combined as a set form a single column name.

See the tweets example here

Though you've said this is in production already, it may not be possible to alter a table with existing data to use compact storage.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top