I was trying to insert a specific timeuuid to cassandra and the only way I managed to insert one was using the now() function, because I assume, the now function knows what format the database likes it.
How do I create cqlsh command for this?
Currently I have this:
INSERT INTO my_table (tid) VALUES ( now() )
But I would like to be able to have 100% control of what date I insert for testing purposes when I am debugging my node.js or whatever program interfacing cassandra.
It would be nice to have something like:
INSERT INTO my_table (tid) VALUES ( 12/OCTOBER/2014 )
without it crashing
Thanks!
timeuuid's are a complex format. Valid values are described here.
timeuuid
Uses the time in 100 nanosecond intervals since 00:00:00.00 UTC (60 bits), a
clock sequence number for prevention of duplicates (14 bits), plus the IEEE 801 MAC
address (48 bits) to generate a unique identifier. For example:
d2177dd0-eaa2-11de-a572-001b779c76e3
This has a good discussion of timeuuid
. I do not know what order these bits appear in, but if it is from left to right you could concat:
Time (first 15 digits = 60 bits): 00000000-0000-000
Sequence (next 3 digits = 12 bits, ignores last 2 bits of sequence): 0-00
Last 2 bits sequence + MAC: 000-000000000000
Then increment the Time or the Sequence as needed for entries. But it would probably be a lot easier to just work with timestamps.
If you want to do this:
INSERT INTO my_table (tid) VALUES ( "2014-10-12" )
you need to use the timestamp
type.
I you have 2 options:
minTimeuuid
or maxTimeuuid
described here
I'd say the first approach would be easier for testing purposes.
Take a look at minTimeuuid
and maxTimeuuid
functions. It's a bad idea to insert their result, but for testing purposes it can be OK.
http://cassandra.apache.org/doc/cql3/CQL.html#timeuuidFun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With