BigDataLearner
BigDataLearner

Reputation: 1468

Get count of elements in Set type column in Cassandra

how to get the count of elements in a column in Cassandra (cql) which is of Set; e.g; a Column in a table has value {'9970GBBHVOB61', '9970GBBHVOB62', '9970GBBHVOB6O'} .I want 3 to be returned from the query

Upvotes: 7

Views: 4753

Answers (2)

GhostCode
GhostCode

Reputation: 454

To give a very specific answer to your question - "Column in a table has value {'9970GBBHVOB61', '9970GBBHVOB62', '9970GBBHVOB6O'} .I want 3 to be returned from the query"

There is a size() method that does just that.. to give an example of how it is used:

 select order_id,items.item_id,last_modified from person.ecommerce_order   where size(items.item_id)> 1

To explain the query:

items.item_id is a list field .The check is if there are more than one item in the list.

Upvotes: -2

Daniel Schulz
Daniel Schulz

Reputation: 574

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. Sorry abut that.

Upvotes: 4

Related Questions