Permalink
Browse files

Using "internal" data type instead of the bigint, removed custom logi…

…c handling 32/64bits (that's handled by "internal" data type now).
  • Loading branch information...
1 parent bda8da0 commit b0ad29438146e0b9997bc737d5e64fab3f2c6201 @tvondra committed Nov 8, 2011
Showing with 170 additions and 59 deletions.
  1. +1 −1 Makefile
  2. +1 −1 quantile.control
  3. +133 −0 sql/quantile--1.1.sql
  4. +35 −57 src/quantile.c
View
@@ -2,7 +2,7 @@ MODULE_big = quantile
OBJS = src/quantile.o
EXTENSION = quantile
-DATA = sql/quantile--1.0.sql
+DATA = sql/quantile--1.0.sql sql/quantile--1.1.sql
MODULES = quantile
CFLAGS=`pg_config --includedir-server`
View
@@ -1,4 +1,4 @@
# quantile aggregate
comment = 'Provides quantile aggregate function.'
-default_version = '1.0'
+default_version = '1.1'
relocatable = true
View
@@ -0,0 +1,133 @@
+/* quantile for the double precision */
+CREATE OR REPLACE FUNCTION quantile_append_double(p_pointer internal, p_element double precision, p_quantile double precision)
+ RETURNS internal
+ AS 'quantile', 'quantile_append_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_append_double_array(p_pointer internal, p_element double precision, p_quantiles double precision[])
+ RETURNS internal
+ AS 'quantile', 'quantile_append_double_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_double(p_pointer internal)
+ RETURNS double precision
+ AS 'quantile', 'quantile_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_double_array(p_pointer internal)
+ RETURNS double precision[]
+ AS 'quantile', 'quantile_double_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE quantile(double precision, double precision) (
+ SFUNC = quantile_append_double,
+ STYPE = internal,
+ FINALFUNC = quantile_double
+);
+
+CREATE AGGREGATE quantile(double precision, double precision[]) (
+ SFUNC = quantile_append_double_array,
+ STYPE = internal,
+ FINALFUNC = quantile_double_array
+);
+
+/* quantile for the numeric */
+CREATE OR REPLACE FUNCTION quantile_append_numeric(p_pointer internal, p_element numeric, p_quantiles double precision)
+ RETURNS internal
+ AS 'quantile', 'quantile_append_numeric'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_append_numeric_array(p_pointer internal, p_element numeric, p_quantiles double precision[])
+ RETURNS internal
+ AS 'quantile', 'quantile_append_numeric_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_numeric(p_pointer internal)
+ RETURNS numeric
+ AS 'quantile', 'quantile_numeric'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_numeric_array(p_pointer internal)
+ RETURNS numeric[]
+ AS 'quantile', 'quantile_numeric_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE quantile(numeric, double precision) (
+ SFUNC = quantile_append_numeric,
+ STYPE = internal,
+ FINALFUNC = quantile_numeric
+);
+
+CREATE AGGREGATE quantile(numeric, double precision[]) (
+ SFUNC = quantile_append_numeric_array,
+ STYPE = internal,
+ FINALFUNC = quantile_numeric_array
+);
+
+/* quantile for the int32 */
+CREATE OR REPLACE FUNCTION quantile_append_int32(p_pointer internal, p_element int, p_quantile double precision)
+ RETURNS internal
+ AS 'quantile', 'quantile_append_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_append_int32_array(p_pointer internal, p_element int, p_quantiles double precision[])
+ RETURNS internal
+ AS 'quantile', 'quantile_append_int32_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_int32(p_pointer internal)
+ RETURNS int
+ AS 'quantile', 'quantile_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_int32_array(p_pointer internal)
+ RETURNS int[]
+ AS 'quantile', 'quantile_int32_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE quantile(int, double precision) (
+ SFUNC = quantile_append_int32,
+ STYPE = internal,
+ FINALFUNC = quantile_int32
+);
+
+CREATE AGGREGATE quantile(int, double precision[]) (
+ SFUNC = quantile_append_int32_array,
+ STYPE = internal,
+ FINALFUNC = quantile_int32_array
+);
+
+/* quantile for the int64 */
+CREATE OR REPLACE FUNCTION quantile_append_int64(p_pointer internal, p_element bigint, p_quantile double precision)
+ RETURNS internal
+ AS 'quantile', 'quantile_append_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_append_int64_array(p_pointer internal, p_element bigint, p_quantiles double precision[])
+ RETURNS internal
+ AS 'quantile', 'quantile_append_int64_array'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_int64(p_pointer internal)
+ RETURNS bigint
+ AS 'quantile', 'quantile_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION quantile_int64_array(p_pointer internal)
+ RETURNS bigint[]
+ AS 'quantile', 'quantile_int64_array'
+ LANGUAGE C IMMUTABLE;
+
+/* actual aggregates */
+
+CREATE AGGREGATE quantile(bigint, double precision) (
+ SFUNC = quantile_append_int64,
+ STYPE = internal,
+ FINALFUNC = quantile_int64
+);
+
+CREATE AGGREGATE quantile(bigint, double precision[]) (
+ SFUNC = quantile_append_int64_array,
+ STYPE = internal,
+ FINALFUNC = quantile_int64_array
+);
Oops, something went wrong.

0 comments on commit b0ad294

Please sign in to comment.