cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Suresh Mahawar <suresh.maha...@technocube.in>
Subject Cassandra: UDF
Date Wed, 05 Aug 2015 10:09:16 GMT
Hi,

I need your help. I have a query which get top 5 records group by date (not
date + time) and sum of amount.

I wrote the following but it returns all the records not just top 5 records

CREATE OR REPLACE FUNCTION state_groupbyandsum( state map<text, double>,
datetime text, amount text )
CALLED ON NULL INPUT
RETURNS map<text, double>
LANGUAGE java
AS 'String date = datetime.substring(0,10); Double count = (Double)
state.get(date);  if (count == null) count = Double.parseDouble(amount);
else count = count +  Double.parseDouble(amount); state.put(date, count);
return state;' ;


CREATE OR REPLACE AGGREGATE groupbyandsum(text, text)
SFUNC state_groupbyandsum
STYPE map<text, double>
INITCOND {};

select groupbyandsum(datetime, amout) from warehouse;

Could you please help out to get just 5 records.


Thanks & Regards,
Suresh Mahawar
TechnoCube
Find Me on Linkedin <https://www.linkedin.com/pub/suresh-mahawar/2a/b9/a80>

Mime
View raw message