Permalink
Browse files

Switched to "internal" data type for handling pointers, various other…

… improvements (handling aggregate context).
  • Loading branch information...
1 parent 41d0ea3 commit a65ef1d4e53f6809a5e782ee6c85cc72c68bc6da @tvondra committed Nov 8, 2011
Showing with 313 additions and 113 deletions.
  1. +5 −1 META.json
  2. +1 −1 Makefile
  3. +253 −0 sql/trimmed_aggregates--1.1.sql
  4. +53 −110 src/trimmed.c
  5. +1 −1 trimmed_aggregates.control
View
6 META.json
@@ -2,7 +2,7 @@
"name": "trimmed_aggregates",
"abstract": "Aggregate for computing trimmed avg/stddev/var (with outliers removed).",
"description": "An extension written in C that allows you to remove outliers before computing the basic statistical aggregates (AVG/STDDEV/VARIANCE).",
- "version": "1.0.0",
+ "version": "1.1.0",
"maintainer": "Tomas Vondra <tv@fuzzy.cz>",
"license": "gpl_3",
"prereqs": {
@@ -16,6 +16,10 @@
"quantile": {
"file": "sql/trimmed_aggregates--1.0.sql",
"version": "1.0.0"
+ },
+ "quantile": {
+ "file": "sql/trimmed_aggregates--1.1.sql",
+ "version": "1.1.0"
}
},
"resources": {
View
2 Makefile
@@ -2,7 +2,7 @@ MODULE_big = trimmed_aggregates
OBJS = src/trimmed.o
EXTENSION = trimmed_aggregates
-DATA = sql/trimmed_aggregates--1.0.sql
+DATA = sql/trimmed_aggregates--1.0.sql sql/trimmed_aggregates--1.1.sql
MODULES = trimmed_aggregates
CFLAGS=`pg_config --includedir-server`
View
253 sql/trimmed_aggregates--1.1.sql
@@ -0,0 +1,253 @@
+/* accumulating data */
+CREATE OR REPLACE FUNCTION trimmed_append_double(p_pointer internal, p_element double precision, p_cut_low double precision default 0, p_cut_up double precision default 0)
+ RETURNS internal
+ AS 'trimmed_aggregates', 'trimmed_append_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_append_int32(p_pointer internal, p_element int, p_cut_low double precision default 0, p_cut_up double precision default 0)
+ RETURNS internal
+ AS 'trimmed_aggregates', 'trimmed_append_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_append_int64(p_pointer internal, p_element bigint, p_cut_low double precision default 0, p_cut_up double precision default 0)
+ RETURNS internal
+ AS 'trimmed_aggregates', 'trimmed_append_int64'
+ LANGUAGE C IMMUTABLE;
+
+/* average */
+CREATE OR REPLACE FUNCTION trimmed_avg_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_avg_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_avg_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_avg_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_avg_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_avg_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE avg_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_avg_double
+);
+
+CREATE AGGREGATE avg_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_avg_int32
+);
+
+CREATE AGGREGATE avg_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_avg_int64
+);
+
+/* variance */
+CREATE OR REPLACE FUNCTION trimmed_var_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_var_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_var_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE var_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_double
+);
+
+CREATE AGGREGATE var_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_int32
+);
+
+CREATE AGGREGATE var_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_int64
+);
+
+/* variance (population estimate) */
+CREATE OR REPLACE FUNCTION trimmed_var_pop_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_pop_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_var_pop_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_pop_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_var_pop_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_pop_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE var_pop_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_pop_double
+);
+
+CREATE AGGREGATE var_pop_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_pop_int32
+);
+
+CREATE AGGREGATE var_pop_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_pop_int64
+);
+
+/* variance (sample estimate) */
+CREATE OR REPLACE FUNCTION trimmed_var_samp_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_samp_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_var_samp_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_samp_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_var_samp_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_var_samp_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE var_samp_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_samp_double
+);
+
+CREATE AGGREGATE var_samp_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_samp_int32
+);
+
+CREATE AGGREGATE var_samp_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_var_samp_int64
+);
+
+/* variance */
+CREATE OR REPLACE FUNCTION trimmed_stddev_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_stddev_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_stddev_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE stddev_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_double
+);
+
+CREATE AGGREGATE stddev_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_int32
+);
+
+CREATE AGGREGATE stddev_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_int64
+);
+
+/* variance (population estimate) */
+CREATE OR REPLACE FUNCTION trimmed_stddev_pop_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_pop_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_stddev_pop_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_pop_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_stddev_pop_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_pop_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE stddev_pop_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_pop_double
+);
+
+CREATE AGGREGATE stddev_pop_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_pop_int32
+);
+
+CREATE AGGREGATE stddev_pop_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_pop_int64
+);
+
+/* variance (sample estimate) */
+CREATE OR REPLACE FUNCTION trimmed_stddev_samp_double(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_samp_double'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_stddev_samp_int32(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_samp_int32'
+ LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION trimmed_stddev_samp_int64(p_pointer internal)
+ RETURNS double precision
+ AS 'trimmed_aggregates', 'trimmed_stddev_samp_int64'
+ LANGUAGE C IMMUTABLE;
+
+CREATE AGGREGATE stddev_samp_trimmed(double precision, double precision, double precision) (
+ SFUNC = trimmed_append_double,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_samp_double
+);
+
+CREATE AGGREGATE stddev_samp_trimmed(int, double precision, double precision) (
+ SFUNC = trimmed_append_int32,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_samp_int32
+);
+
+CREATE AGGREGATE stddev_samp_trimmed(bigint, double precision, double precision) (
+ SFUNC = trimmed_append_int64,
+ STYPE = internal,
+ FINALFUNC = trimmed_stddev_samp_int64
+);
View
163 src/trimmed.c
@@ -18,19 +18,16 @@
PG_MODULE_MAGIC;
#endif
-#if __WORDSIZE == 64
-#define GET_POINTER(a,b) (a*)(b)
-#define GET_INTEGER(a) ((int64)a)
-#else
-#define GET_POINTER(a,b) (a*)((int32)b)
-#define GET_INTEGER(a) ((int32)a)
-#endif
-
#define GET_AGG_CONTEXT(fname, fcinfo, aggcontext) \
if (! AggCheckCallContext(fcinfo, &aggcontext)) { \
elog(ERROR, "%s called in non-aggregate context", fname); \
}
+#define CHECK_AGG_CONTEXT(fname, fcinfo) \
+ if (! AggCheckCallContext(fcinfo, NULL)) { \
+ elog(ERROR, "%s called in non-aggregate context", fname); \
+ }
+
#define SLICE_SIZE 1024
/* Structures used to keep the data - the 'elements' array is extended
@@ -193,7 +190,7 @@ trimmed_append_double(PG_FUNCTION_ARGS)
data->cut_upper = PG_GETARG_FLOAT8(3);
} else {
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
}
if (! PG_ARGISNULL(1)) {
@@ -210,7 +207,7 @@ trimmed_append_double(PG_FUNCTION_ARGS)
MemoryContextSwitchTo(oldcontext);
- PG_RETURN_INT64(GET_INTEGER(data));
+ PG_RETURN_POINTER(data);
}
@@ -241,7 +238,7 @@ trimmed_append_int32(PG_FUNCTION_ARGS)
data->cut_upper = PG_GETARG_FLOAT8(3);
} else {
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
}
if (! PG_ARGISNULL(1)) {
@@ -259,7 +256,7 @@ trimmed_append_int32(PG_FUNCTION_ARGS)
MemoryContextSwitchTo(oldcontext);
- PG_RETURN_INT64(GET_INTEGER(data));
+ PG_RETURN_POINTER(data);
}
@@ -290,7 +287,7 @@ trimmed_append_int64(PG_FUNCTION_ARGS)
data->cut_upper = PG_GETARG_FLOAT8(3);
} else {
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
}
if (! PG_ARGISNULL(1)) {
@@ -308,7 +305,7 @@ trimmed_append_int64(PG_FUNCTION_ARGS)
MemoryContextSwitchTo(oldcontext);
- PG_RETURN_INT64(GET_INTEGER(data));
+ PG_RETURN_POINTER(data);
}
@@ -322,15 +319,13 @@ trimmed_avg_double(PG_FUNCTION_ARGS)
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_avg_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_avg_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -360,15 +355,13 @@ trimmed_avg_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_avg_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_avg_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -398,15 +391,13 @@ trimmed_avg_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_avg_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_avg_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -437,15 +428,13 @@ trimmed_var_double(PG_FUNCTION_ARGS)
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -480,15 +469,13 @@ trimmed_var_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -523,15 +510,13 @@ trimmed_var_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -563,18 +548,15 @@ trimmed_var_pop_double(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_pop_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_pop_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -603,18 +585,15 @@ trimmed_var_pop_int32(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_pop_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_pop_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -643,18 +622,15 @@ trimmed_var_pop_int64(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_pop_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_pop_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -683,18 +659,15 @@ trimmed_var_samp_double(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_samp_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_samp_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -723,18 +696,15 @@ trimmed_var_samp_int32(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_samp_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_samp_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -763,18 +733,15 @@ trimmed_var_samp_int64(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_var_samp_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_var_samp_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -806,15 +773,13 @@ trimmed_stddev_double(PG_FUNCTION_ARGS)
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -849,15 +814,13 @@ trimmed_stddev_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -892,15 +855,13 @@ trimmed_stddev_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -933,18 +894,15 @@ trimmed_stddev_pop_double(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_pop_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_pop_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -973,18 +931,15 @@ trimmed_stddev_pop_int32(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_pop_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_pop_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -1013,18 +968,15 @@ trimmed_stddev_pop_int64(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_pop_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_pop_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -1053,18 +1005,15 @@ trimmed_stddev_samp_double(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_double * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_samp_double", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_samp_double", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_double, PG_GETARG_INT64(0));
+ data = (struct_double*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -1093,18 +1042,15 @@ trimmed_stddev_samp_int32(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int32 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_samp_int32", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_samp_int32", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int32, PG_GETARG_INT64(0));
+ data = (struct_int32*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
@@ -1133,18 +1079,15 @@ trimmed_stddev_samp_int64(PG_FUNCTION_ARGS)
double sum_x = 0, sum_x2 = 0;
int from, to, cnt;
-
struct_int64 * data;
- MemoryContext aggcontext;
-
- GET_AGG_CONTEXT("trimmed_stddev_samp_int64", fcinfo, aggcontext);
+ CHECK_AGG_CONTEXT("trimmed_stddev_samp_int64", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
- data = GET_POINTER(struct_int64, PG_GETARG_INT64(0));
+ data = (struct_int64*)PG_GETARG_POINTER(0);
from = floor(data->next * data->cut_lower);
to = data->next - floor(data->next * data->cut_upper);
View
2 trimmed_aggregates.control
@@ -1,4 +1,4 @@
# trimmed aggregates
comment = 'Provides trimmed aggregate functions.'
-default_version = '1.0'
+default_version = '1.1'
relocatable = true

0 comments on commit a65ef1d

Please sign in to comment.