Cassandra : Select records based on "timeuuid where conditions"

Mohd Shahid picture Mohd Shahid · Jan 25, 2016 · Viewed 7.3k times · Source

I created one table in Cassandra and want to select data based on where condition of the column which has timeuuid type.

CREATE TABLE shahid.stock_ticks(
symbol varchar,
date int,
trade timeuuid,
trade_details text,
PRIMARY KEY (  (symbol, date), trade   )
) WITH CLUSTERING ORDER BY (trade DESC) ;

INSERT INTO shahid.stock_ticks (symbol, date, trade, trade_details) VALUES ('NFLX', 1, now(), 'this is 10' );
INSERT INTO shahid.stock_ticks (symbol, date, trade, trade_details) VALUES ('NFLX', 1, now(), 'this is 2' );
INSERT INTO shahid.stock_ticks (symbol, date, trade, trade_details) VALUES ('NFLX', 1, now(), 'this is 3' );

Above query has inserted records and one record has value '2045d660-9415-11e5-9742-c53da2f1a8ec' in trade column.

I want to select like this but it is giving error

select * from shahid.stock_ticks  where symbol = 'NFLX' and date = 1 and trade < '2045d660-9415-11e5-9742-c53da2f1a8ec';

It is giving below error

InvalidQueryException: Invalid STRING constant (2045d660-9415-11e5-9742-c53da2f1a8ec) for "trade" of type timeuuid

I tried below queries also with no luck

select * from shahid.stock_ticks  where symbol = 'NFLX' and date = 1 and trade < maxTimeuuid('2045d660-9415-11e5-9742-c53da2f1a8ec');
select * from shahid.stock_ticks  where symbol = 'NFLX' and date = 1 and trade < dateOf('2045d660-9415-11e5-9742-c53da2f1a8ec');
select * from shahid.stock_ticks  where symbol = 'NFLX' and date = 1 and trade < unixTimestampOf('2045d660-9415-11e5-9742-c53da2f1a8ec');

Answer

Jan D&#246;rrenhaus picture Jan Dörrenhaus · Jan 25, 2016

Remove the quotes around your UUID. Cassandra has native support for them, not via Strings.

select * from shahid.stock_ticks  where symbol = 'NFLX' and date = 1 and trade < 2045d660-9415-11e5-9742-c53da2f1a8ec;