Search code examples
cassandracql3cqlsh

Cassandra SUM(Map <text,int>) is it possible?


In Casssandra is it possible to sum of int values in a My DB structure is attr Map<text,int> is it possible to use select sum (attr['salary']) from testtable or something equivalent


Solution

  • Cassandra not support Map, List and Set in the Select,Insert with [] ( Ex: attr['salary'] )

    You can use User Defined Data Type.

    Example:

    Define your user defined data type like as below

    mytype {
    
    salary (int)
    
    }
    

    create 'attr' field with type 'mytype'

    now you can do query like as below

    select sum(attr.salary) from yourtable.