Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a hard-coded UUID via CQLsh (Cassandra)

Would like to populate some static test data via a CQLsh script.

This doesn't work: (device_id is UUID)

insert into devices (device_id, geohash,name, external_identifier, measures, tags)  values ('c37d661d-7e61-49ea-96a5-68c34e83db3a','9q9p3yyrn1', 'Acme1', '936', {'aparPower','actPower','actEnergy'},{'make':'Acme'}); 

Bad Request: Invalid STRING constant (c37d661d-7e61-49ea-96a5-68c34e83db3a) for device_id of type uuid

I can't seem to find any CQL function to convert to proper type. Do I need to do this from a python script?

Thanks, Chris

like image 650
Chris H Avatar asked Sep 27 '13 16:09

Chris H


People also ask

What is a UUID in Cassandra?

A UUID is a Universally Unique ID used to avoid collisions. Cassandra 2.0.7 and later versions include the uuid () function that takes no parameters and generates a Type 4 UUID for use in INSERT or SET statements. You can also use a timeuuid type with a function like now (). They generate a Type 1 UUID.

How to run Cassandra query language shell?

Hence, a user can program Cassandra to work according to his requirement. When working on a Linux operating system, a user can start Cassandra Query Language Shell by executing simple command ‘cqlsh’. Whereas, when working in a Windows operating system, a user has to execute ‘python cqlsh’ to run cqlsh.

How do I insert data from a CSV file into Cassandra?

If you want to store data in bulk then inserting data from a CSV file is one of the nice ways. If you have data in a file so, you can directly insert your data into the database by using the COPY command in Cassandra.

How to generate a random Type 4 UUID in Cassandra?

insert into stuff (uid, name) values (nextuid (), 'my name'); As of Cassandra 2.0.7 you can just use uuid (), which generates a random type 4 UUID: Thanks for that you made my day! Thanks for the updated answer for newer versions of cassandra!


Video Answer


1 Answers

You shouldn't put the quotes around the UUID to stop it being interpreted as a string i.e.

insert into devices (device_id, geohash,name, external_identifier, measures, tags)   values  (c37d661d-7e61-49ea-96a5-68c34e83db3a,'9q9p3yyrn1', 'Acme1', '936', {'aparPower','actPower','actEnergy'},{'make':'Acme'}); 
like image 120
Richard Avatar answered Sep 23 '22 02:09

Richard