forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testing AGGREGATE statements and fix aggregatesTemplate
- Loading branch information
1 parent
fa8da7c
commit 6fb0901
Showing
5 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CREATE KEYSPACE gocqlx_aggregates WITH replication = { | ||
'class': 'SimpleStrategy', | ||
'replication_factor': '2' | ||
}; | ||
|
||
CREATE FUNCTION gocqlx_aggregates.avgstate( | ||
state tuple<int, double>, | ||
val double) | ||
CALLED ON NULL INPUT | ||
RETURNS frozen<tuple<int, double>> | ||
LANGUAGE lua | ||
AS $$ | ||
return { state[1]+1, state[2]+val } | ||
$$; | ||
|
||
CREATE FUNCTION gocqlx_aggregates.avgfinal( | ||
state tuple<int, double>) | ||
CALLED ON NULL INPUT | ||
RETURNS double | ||
LANGUAGE lua | ||
as $$ | ||
r=0 | ||
r=state[2] | ||
r=r/state[1] | ||
return r | ||
$$; | ||
|
||
CREATE AGGREGATE gocqlx_aggregates.average(double) | ||
SFUNC avgstate STYPE tuple<int, double> | ||
FINALFUNC avgfinal | ||
INITCOND (0,0.0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
CREATE KEYSPACE gocqlx_aggregates WITH replication = { | ||
'class': 'SimpleStrategy', | ||
'replication_factor': '2' | ||
}; | ||
|
||
CREATE FUNCTION gocqlx_aggregates.avgstate (state | ||
tuple<int, double>, val | ||
double) | ||
CALLED ON NULL INPUT | ||
RETURNS frozen<tuple<int, double>> | ||
LANGUAGE lua | ||
AS $$ | ||
return { state[1]+1, state[2]+val } | ||
$$; | ||
|
||
CREATE FUNCTION gocqlx_aggregates.avgfinal (state | ||
tuple<int, double>) | ||
CALLED ON NULL INPUT | ||
RETURNS double | ||
LANGUAGE lua | ||
AS $$ | ||
r=0 | ||
r=state[2] | ||
r=r/state[1] | ||
return r | ||
$$; | ||
|
||
CREATE AGGREGATE gocqlx_aggregates.average( | ||
double) | ||
SFUNC avgstate | ||
STYPE tuple<int, double> | ||
FINALFUNC avgfinal | ||
INITCOND (0, 0); |