Get count of elements in Set type column in Cassandra

青春壹個敷衍的年華 提交于 2019-12-08 19:12:33

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/22334704/get-count-of-elements-in-set-type-column-in-cassandra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!