Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra : Select records based on "timeuuid where conditions"

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');
like image 358
Mohd Shahid Avatar asked Dec 05 '22 19:12

Mohd Shahid


1 Answers

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;
like image 82
Jan Dörrenhaus Avatar answered Jan 06 '23 11:01

Jan Dörrenhaus