CQL中是否存在sum函数描述?

时间:2015-08-14 11:49:49

标签: java cassandra sum cql

我可以轻松地从DevCenter执行查询:

SELECT sum(count) FROM myTable;

但我发现sum中的cql函数没有任何专注。它存在吗? cassandra团队发布了具有count功能和其他功能的功能列表?

注意

This function listcountsum一无所知。

2 个答案:

答案 0 :(得分:3)

sum()和avg()函数似乎在Cassandra 2.2和SELECT语句的3.0-alpha中有效,但它们似乎还没有出现在文档中。

它们应该记录在2.2 CQL参考here中。我想在3.0正式发布时,他们将努力更新文档。

它们看起来很容易使用:

cqlsh:test> CREATE table t1 ( a int, b int, primary key (a));
cqlsh:test> INSERT INTO t1 (a, b) VALUES ( 1, 2);
cqlsh:test> INSERT INTO t1 (a, b) VALUES ( 3, 4);
cqlsh:test> SELECT sum (b) from t1;

 system.sum(b)
---------------
             6

(1 rows)
cqlsh:test> SELECT avg (b) from t1;

 system.avg(b)
---------------
             3

很高兴终于内置了基本的聚合函数。现在,如果有人只是使用类似Spark的方法实现基本连接,那么我们将使用gas来烹饪。 :)

为了回答您的问题,这些函数似乎在此文件中实现(如果您下载源代码):

src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java

Cassandra 2.2中实现的功能是:sum(),avg(),max(),min()和count()。

答案 1 :(得分:1)

Cassandra不支持聚合函数作为CQL标准的一部分。但是从Cassandra 2.2开始,您将能够创建自己的函数(UDA),这将允许您实现总和计算。

相关问题