Search This Blog

Showing posts with label Select. Show all posts
Showing posts with label Select. Show all posts

Tuesday, November 28, 2017

Cassandra Group By clause in Select command

1. Go to C:\Program Files\DataStax-DDC\apache-cassandra\conf\cassandra.yaml
change false to true

enable_user_defined_functions: true


2. Paste below functions in cqlsh window

CREATE OR REPLACE FUNCTION state_group_and_count( state map, type text )
CALLED ON NULL INPUT
RETURNS map
LANGUAGE java AS '
Integer count = (Integer) state.get(type);  if (count == null) count = 1; else count++; state.put(type, count); return state; ' ;

CREATE OR REPLACE AGGREGATE group_and_count(text)
SFUNC state_group_and_count
STYPE map 
INITCOND {};


3. execute the query like below

--select group_and_count(column) from table;
-- ex
-- select group_and_count(item) from skutable;



4. you may see like this 
Failed to format value OrderedMapSerializedKey([(u'xxx', 4)]) : 'NoneType' object has no attribute 'sub_types'
this is a cqlsh error. so you can try from programming languages like java..., it may work perfectly.

Hit Counter


View My Stats