Table:
CREATE TABLE IF NOT EXISTS table (
a TEXT,
b TEXT,
c BIGINT,
PRIMARY KEY ((a, b), c)
) WITH CLUSTERING ORDER BY (c DESC);
I need to get only one record from each (a, b) partition for the entire selection where c will be in DESC order and b in ASC order:
SELECT * FROM table WHERE a='a-1' ORDER BY b ASC PER PARTITION LIMIT 1 ALLOW FILTERING;
Result:
ORDER BY is only supported when the partition key is restricted by an EQ or an IN.
I tried create materialized view for ordering by b:
CREATE MATERIALIZED VIEW IF NOT EXISTS table_view AS
SELECT a, b, c
FROM table
WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL
PER PARTITION LIMIT 1
PRIMARY KEY (a, b, c)
WITH CLUSTERING ORDER BY (b ASC, c DESC);
I get an error while creating on PER PARTITION LIMIT.
Is it really possible to do this? Or maybe there is some workaround for this case?