Упомянутая вами схема
CREATE TABLE temp.school (
roll_no text PRIMARY KEY,
count int,
name text
)
Пример ввода в таблицу
roll_no | count | name
---------+-------+------
6 | 1 | b
7 | 1 | null
4 | 1 | b
3 | 1 | a
5 | 1 | b
2 | 1 | a
1 | 1 | a
(7 rows)
Примечание. В столбце имени есть одно нулевое значение.
Измененная функцияопределение
CREATE FUNCTION temp.state_group_and_total(state map<text, int>, type text, amount int)
RETURNS NULL 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;$$;
Примечание: удалено CALLED ON NULL INPUT
и добавлено RETURNS NULL ON NULL INPUT
Совокупное определение:
CREATE AGGREGATE temp.group_and_total(text, int)
SFUNC state_group_and_total
STYPE map<text, int>
INITCOND {};
Вывод запроса:
cassandra@cqlsh:temp> select group_and_total(name,count) from school;
temp.group_and_total(name, count)
-----------------------------------
{'a': 3, 'b': 3}
(1 rows)