Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simplified handling of calls in non-aggregate context.

  • Loading branch information...
commit 41d0ea3fd6b39240a3cc2928e7b34344f154f945 1 parent cc3068e
Tomas Vondra authored
Showing with 96 additions and 13 deletions.
  1. +96 −13 src/trimmed.c
109 src/trimmed.c
View
@@ -26,6 +26,11 @@ PG_MODULE_MAGIC;
#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 SLICE_SIZE 1024
/* Structures used to keep the data - the 'elements' array is extended
@@ -171,11 +176,9 @@ trimmed_append_double(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
MemoryContext aggcontext;
-
- if (! AggCheckCallContext(fcinfo, &aggcontext)) {
- elog(ERROR, "quantile_append_double called in non-aggregate context");
- }
-
+
+ GET_AGG_CONTEXT("quantile_append_double", fcinfo, aggcontext);
+
oldcontext = MemoryContextSwitchTo(aggcontext);
if (PG_ARGISNULL(0)) {
@@ -221,10 +224,8 @@ trimmed_append_int32(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
MemoryContext aggcontext;
-
- if (! AggCheckCallContext(fcinfo, &aggcontext)) {
- elog(ERROR, "quantile_append_double called in non-aggregate context");
- }
+
+ GET_AGG_CONTEXT("quantile_append_int32", fcinfo, aggcontext);
oldcontext = MemoryContextSwitchTo(aggcontext);
@@ -272,10 +273,8 @@ trimmed_append_int64(PG_FUNCTION_ARGS)
MemoryContext oldcontext;
MemoryContext aggcontext;
-
- if (! AggCheckCallContext(fcinfo, &aggcontext)) {
- elog(ERROR, "quantile_append_double called in non-aggregate context");
- }
+
+ GET_AGG_CONTEXT("quantile_append_64", fcinfo, aggcontext);
oldcontext = MemoryContextSwitchTo(aggcontext);
@@ -323,6 +322,10 @@ trimmed_avg_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_avg_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -357,6 +360,10 @@ trimmed_avg_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_avg_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -391,6 +398,10 @@ trimmed_avg_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_avg_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -426,6 +437,10 @@ trimmed_var_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -465,6 +480,10 @@ trimmed_var_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -504,6 +523,10 @@ trimmed_var_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -543,6 +566,10 @@ trimmed_var_pop_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_pop_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -579,6 +606,10 @@ trimmed_var_pop_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_pop_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -615,6 +646,10 @@ trimmed_var_pop_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_pop_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -651,6 +686,10 @@ trimmed_var_samp_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_samp_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -687,6 +726,10 @@ trimmed_var_samp_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_samp_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -723,6 +766,10 @@ trimmed_var_samp_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_var_samp_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -759,6 +806,10 @@ trimmed_stddev_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -798,6 +849,10 @@ trimmed_stddev_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -837,6 +892,10 @@ trimmed_stddev_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -877,6 +936,10 @@ trimmed_stddev_pop_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_pop_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -913,6 +976,10 @@ trimmed_stddev_pop_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_pop_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -949,6 +1016,10 @@ trimmed_stddev_pop_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_pop_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -985,6 +1056,10 @@ trimmed_stddev_samp_double(PG_FUNCTION_ARGS)
struct_double * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_samp_double", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -1021,6 +1096,10 @@ trimmed_stddev_samp_int32(PG_FUNCTION_ARGS)
struct_int32 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_samp_int32", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
@@ -1057,6 +1136,10 @@ trimmed_stddev_samp_int64(PG_FUNCTION_ARGS)
struct_int64 * data;
+ MemoryContext aggcontext;
+
+ GET_AGG_CONTEXT("trimmed_stddev_samp_int64", fcinfo, aggcontext);
+
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
Please sign in to comment.
Something went wrong with that request. Please try again.