Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Cassandra CQL, is there a way to query the size of a collection column type?

Tags:

cassandra

cql

We're looking to be able to do something like..

select * from User where rewards.size > 0

when the schema is

create table user (
    id uuid primary key,
    network_id uuid,
    rewards set<uuid>,
    name text   
);
like image 840
mmlac Avatar asked Dec 12 '13 22:12

mmlac


People also ask

What is not allowed in CQL query?

CQL does not support wildcard queries. CQL does not support Union, Intersection queries. Table columns cannot be filtered without creating the index. Greater than (>) and less than (<) query is only supported on clustering column.

What is Cqlsh command?

cqlsh is a command-line interface for interacting with Cassandra using CQL (the Cassandra Query Language). It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable.


1 Answers

sadly Cassandra is eager performing very quick reads and on the other hand is not perfectly done supporting collections: Get count of elements in Set type column in Cassandra

unfortunately the Collections-support even in CQL Driver v2 is not perfect: you may add or delete items in upsert statements. But more on them, like doing an item select, asking for collection item's TTLs or asking for the collection's size, is not supported. So you have to

resultset: SELECT collection_column FROM ... and then take item by resultset.one() or resultset.all() and get item.size() yourself.

What you want to do is adding an indexed column with a counter to count and fast-read the element count. Iff you just want to know whether the collection is not empty you may need an index column with a boolean. The index makes sure you can scan the columns efficiently.

like image 133
Daniel Schulz Avatar answered Oct 11 '22 14:10

Daniel Schulz