Cassandra : Select records based on "timeuuid where conditions"
Asked Answered
L

1

5

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');
Looker answered 25/1, 2016 at 12:47 Comment(0)
P
16

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;
Pelagi answered 25/1, 2016 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.