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.
Merge pull request #152 from sylwiaszunejko/aggregate_bug
Fix aggregate bug
- Loading branch information
Showing
6 changed files
with
83 additions
and
7 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
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); |