Hi ,

I have a tables as below:

CREATE TABLE test.cs (
>     pid bigint,
>     cid bigint,
>     stat_object text,
>     status int,
>     PRIMARY KEY (pid, cid)
> ) WITH CLUSTERING ORDER BY (cid ASC)


How can I have a function like below :

CREATE or REPLACE FUNCTION test.countstatusobjs (state map<int,
>  map<bigint,text>> , status int , cid bigint , stat_object text)
>     RETURNS NULL ON NULL INPUT RETURNS map<int,int> LANGUAGE java AS 'if
> (state.containsKey(status)) {
>     Map<Long,String> mm = (Map) state.get(status);
>     mm.put(cid, text);
>     state.put(status , mm);
>     }else {
>     Map<Long,String> mm = new HashMap<Long,String>();
>     mm.put(cid, text);
>     state.put(status , mm);
>     }
>     return state;';


To have map of cid,stat_object for a given status.


I was succeed in getting count of each status using below funcitons:

CREATE or REPLACE FUNCTION test.countstatus (state map<int,int> , status
> int)
>     RETURNS NULL ON NULL INPUT RETURNS map<int,int> LANGUAGE java AS 'if
> (state.containsKey(status)) {
>     state.put(status , (Integer) state.get(status) + 1);
>     }else {
>     state.put(status , 1);
>     }
>     return state;';


CREATE or REPLACE AGGREGATE groupbystatus (int)
>         SFUNC countstatus STYPE map<int,int>
>         INITCOND{};


select groupbystatus(status) from test.cs where pid=1;
>  test.groupbystatus(status)
> ----------------------------
>    {0: 2, 1: 3, 2: 1, 5: 1}



In the same way I want to achieve Map<status , Map<cid,stat_object>> .
How can I do the same  ?
Using c*-2.2.8

Thanks in advance
TechPyaasa

Reply via email to