You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2021/06/15 21:58:05 UTC
[datasketches-postgresql] 01/01: fixed treatment of default
parameters
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch fix_default_params
in repository https://gitbox.apache.org/repos/asf/datasketches-postgresql.git
commit 0530cc16ab6cbd8123b34159cb7ece4dab44eebf
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jun 15 14:57:32 2021 -0700
fixed treatment of default parameters
---
src/aod_sketch_pg_functions.c | 17 +++++------------
src/cpc_sketch_pg_functions.c | 7 +++----
src/hll_sketch_pg_functions.c | 3 +--
src/kll_float_sketch_pg_functions.c | 3 +--
src/theta_sketch_pg_functions.c | 3 +--
5 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/src/aod_sketch_pg_functions.c b/src/aod_sketch_pg_functions.c
index a1f0673..d3d27cc 100644
--- a/src/aod_sketch_pg_functions.c
+++ b/src/aod_sketch_pg_functions.c
@@ -173,8 +173,7 @@ Datum pg_aod_sketch_get_estimate_and_bounds(PG_FUNCTION_ARGS) {
bytes_in = PG_GETARG_BYTEA_P(0);
sketchptr = aod_sketch_deserialize(VARDATA(bytes_in), VARSIZE(bytes_in) - VARHDRSZ);
- num_std_devs = PG_GETARG_INT32(1);
- if (num_std_devs == 0) num_std_devs = 1; // default
+ num_std_devs = PG_NARGS() > 1 ? PG_GETARG_INT32(1) : 1;
est_and_bounds = (Datum*) aod_sketch_get_estimate_and_bounds(sketchptr, num_std_devs);
compact_aod_sketch_delete(sketchptr);
@@ -190,11 +189,7 @@ Datum pg_aod_sketch_to_string(PG_FUNCTION_ARGS) {
bool print_entries;
char* str;
bytes_in = PG_GETARG_BYTEA_P(0);
- if (PG_NARGS() > 1) {
- print_entries = PG_GETARG_BOOL(1);
- } else {
- print_entries = false;
- }
+ print_entries = PG_NARGS() > 1 ? PG_GETARG_BOOL(1) : false;
sketchptr = aod_sketch_deserialize(VARDATA(bytes_in), VARSIZE(bytes_in) - VARHDRSZ);
str = aod_sketch_to_string(sketchptr, print_entries);
compact_aod_sketch_delete(sketchptr);
@@ -390,9 +385,8 @@ Datum pg_aod_sketch_union(PG_FUNCTION_ARGS) {
int num_values;
int lg_k;
- num_values = PG_GETARG_INT32(2);
- if (num_values == 0) num_values = 1;
- lg_k = PG_GETARG_INT32(3);
+ num_values = PG_NARGS() > 2 ? PG_GETARG_INT32(2) : 1;
+ lg_k = PG_NARGS() > 3 ? PG_GETARG_INT32(3) : 0;
unionptr = lg_k ? aod_union_new_lgk(num_values, lg_k) : aod_union_new(num_values);
if (!PG_ARGISNULL(0)) {
bytes_in1 = PG_GETARG_BYTEA_P(0);
@@ -424,8 +418,7 @@ Datum pg_aod_sketch_intersection(PG_FUNCTION_ARGS) {
struct ptr_with_size bytes_out;
int num_values;
- num_values = PG_GETARG_INT32(2);
- if (num_values == 0) num_values = 1;
+ num_values = PG_NARGS() > 2 ? PG_GETARG_INT32(2) : 1;
interptr = aod_intersection_new(num_values);
if (!PG_ARGISNULL(0)) {
bytes_in1 = PG_GETARG_BYTEA_P(0);
diff --git a/src/cpc_sketch_pg_functions.c b/src/cpc_sketch_pg_functions.c
index 00a521e..2d0d626 100644
--- a/src/cpc_sketch_pg_functions.c
+++ b/src/cpc_sketch_pg_functions.c
@@ -129,8 +129,7 @@ Datum pg_cpc_sketch_get_estimate_and_bounds(PG_FUNCTION_ARGS) {
bytes_in = PG_GETARG_BYTEA_P(0);
sketchptr = cpc_sketch_deserialize(VARDATA(bytes_in), VARSIZE(bytes_in) - VARHDRSZ);
- num_std_devs = PG_GETARG_INT32(1);
- if (num_std_devs == 0) num_std_devs = 1; // default
+ num_std_devs = PG_NARGS() > 1 ? PG_GETARG_INT32(1) : 1;
est_and_bounds = (Datum*) cpc_sketch_get_estimate_and_bounds(sketchptr, num_std_devs);
cpc_sketch_delete(sketchptr);
@@ -272,8 +271,8 @@ Datum pg_cpc_sketch_union(PG_FUNCTION_ARGS) {
struct ptr_with_size bytes_out;
int lg_k;
- lg_k = PG_GETARG_INT32(2);
- unionptr = cpc_union_new(lg_k ? lg_k : CPC_DEFAULT_LG_K);
+ lg_k = PG_NARGS() > 2 ? PG_GETARG_INT32(2) : CPC_DEFAULT_LG_K;
+ unionptr = cpc_union_new(lg_k);
if (!PG_ARGISNULL(0)) {
bytes_in1 = PG_GETARG_BYTEA_P(0);
sketchptr1 = cpc_sketch_deserialize(VARDATA(bytes_in1), VARSIZE(bytes_in1) - VARHDRSZ);
diff --git a/src/hll_sketch_pg_functions.c b/src/hll_sketch_pg_functions.c
index 4de4b68..743cced 100644
--- a/src/hll_sketch_pg_functions.c
+++ b/src/hll_sketch_pg_functions.c
@@ -138,8 +138,7 @@ Datum pg_hll_sketch_get_estimate_and_bounds(PG_FUNCTION_ARGS) {
bytes_in = PG_GETARG_BYTEA_P(0);
sketchptr = hll_sketch_deserialize(VARDATA(bytes_in), VARSIZE(bytes_in) - VARHDRSZ);
- num_std_devs = PG_GETARG_INT32(1);
- if (num_std_devs == 0) num_std_devs = 1; // default
+ num_std_devs = PG_NARGS() > 1 ? PG_GETARG_INT32(1) : 1;
est_and_bounds = (Datum*) hll_sketch_get_estimate_and_bounds(sketchptr, num_std_devs);
hll_sketch_delete(sketchptr);
diff --git a/src/kll_float_sketch_pg_functions.c b/src/kll_float_sketch_pg_functions.c
index 3e31159..44ab20f 100644
--- a/src/kll_float_sketch_pg_functions.c
+++ b/src/kll_float_sketch_pg_functions.c
@@ -358,8 +358,7 @@ Datum pg_kll_float_sketch_get_histogram(PG_FUNCTION_ARGS) {
bytes_in = PG_GETARG_BYTEA_P(0);
sketchptr = kll_float_sketch_deserialize(VARDATA(bytes_in), VARSIZE(bytes_in) - VARHDRSZ);
- num_bins = PG_GETARG_INT32(1);
- if (num_bins == 0) num_bins = DEFAULT_NUM_BINS;
+ num_bins = PG_NARGS() > 1 ? PG_GETARG_INT32(1) : DEFAULT_NUM_BINS;
if (num_bins < 2) {
elog(ERROR, "at least two bins expected");
}
diff --git a/src/theta_sketch_pg_functions.c b/src/theta_sketch_pg_functions.c
index 04f64bf..00b8195 100644
--- a/src/theta_sketch_pg_functions.c
+++ b/src/theta_sketch_pg_functions.c
@@ -141,8 +141,7 @@ Datum pg_theta_sketch_get_estimate_and_bounds(PG_FUNCTION_ARGS) {
bytes_in = PG_GETARG_BYTEA_P(0);
sketchptr = theta_sketch_deserialize(VARDATA(bytes_in), VARSIZE(bytes_in) - VARHDRSZ);
- num_std_devs = PG_GETARG_INT32(1);
- if (num_std_devs == 0) num_std_devs = 1; // default
+ num_std_devs = PG_NARGS() > 1 ? PG_GETARG_INT32(1) : 1;
est_and_bounds = (Datum*) theta_sketch_get_estimate_and_bounds(sketchptr, num_std_devs);
theta_sketch_delete(sketchptr);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org