Skip to content

Instantly share code, notes, and snippets.

@Sathiyarajan
Forked from chbatey/UDFs.cql
Created March 12, 2018 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sathiyarajan/7fe67c152880efa9cb3214e4dfcdeef9 to your computer and use it in GitHub Desktop.
Save Sathiyarajan/7fe67c152880efa9cb3214e4dfcdeef9 to your computer and use it in GitHub Desktop.
CREATE FUNCTION state_group_and_total( state map<text, int>, type text, amount int )
CALLED ON NULL INPUT
RETURNS map<text, int>
LANGUAGE java AS '
Integer count = (Integer) state.get(type); if (count == null) count = amount; else count = count + amount; state.put(type, count); return state; ' ;
CREATE OR REPLACE AGGREGATE group_and_total(text, int)
SFUNC state_group_and_total
STYPE map<text, int>
INITCOND {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment