This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch theta
in repository
https://gitbox.apache.org/repos/asf/incubator-datasketches-postgresql.git
The following commit(s) were added to refs/heads/theta by this push:
new 88381f0 support sampling probability parameter
88381f0 is described below
commit 88381f0b2980958d13f7833b98930e563aee79a1
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Tue Jun 11 15:06:37 2019 -0700
support sampling probability parameter
---
sql/datasketches_theta_sketch.sql | 10 ++++++++++
src/theta_sketch_c_adapter.cpp | 10 +++++++++-
src/theta_sketch_c_adapter.h | 3 ++-
src/theta_sketch_pg_functions.c | 8 +++++++-
4 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/sql/datasketches_theta_sketch.sql
b/sql/datasketches_theta_sketch.sql
index eb46d6d..4927795 100644
--- a/sql/datasketches_theta_sketch.sql
+++ b/sql/datasketches_theta_sketch.sql
@@ -28,6 +28,10 @@ CREATE OR REPLACE FUNCTION theta_sketch_add_item(internal,
anyelement, int) RETU
AS '$libdir/datasketches', 'pg_theta_sketch_add_item'
LANGUAGE C IMMUTABLE;
+CREATE OR REPLACE FUNCTION theta_sketch_add_item(internal, anyelement, int,
real) RETURNS internal
+ AS '$libdir/datasketches', 'pg_theta_sketch_add_item'
+ LANGUAGE C IMMUTABLE;
+
CREATE OR REPLACE FUNCTION theta_sketch_get_estimate(theta_sketch) RETURNS
double precision
AS '$libdir/datasketches', 'pg_theta_sketch_get_estimate'
LANGUAGE C STRICT IMMUTABLE;
@@ -80,6 +84,12 @@ CREATE AGGREGATE theta_sketch_build(anyelement, int) (
finalfunc = theta_sketch_from_internal
);
+CREATE AGGREGATE theta_sketch_build(anyelement, int, real) (
+ sfunc = theta_sketch_add_item,
+ stype = internal,
+ finalfunc = theta_sketch_from_internal
+);
+
CREATE AGGREGATE theta_sketch_union(theta_sketch) (
sfunc = theta_sketch_union_agg,
stype = internal,
diff --git a/src/theta_sketch_c_adapter.cpp b/src/theta_sketch_c_adapter.cpp
index fb71142..76843ad 100644
--- a/src/theta_sketch_c_adapter.cpp
+++ b/src/theta_sketch_c_adapter.cpp
@@ -32,7 +32,7 @@ void* theta_sketch_new_default() {
}
}
-void* theta_sketch_new(unsigned lg_k) {
+void* theta_sketch_new_lgk(unsigned lg_k) {
try {
return new (palloc(sizeof(update_theta_sketch_pg)))
update_theta_sketch_pg(update_theta_sketch_pg::builder().set_lg_k(lg_k).build());
} catch (std::exception& e) {
@@ -40,6 +40,14 @@ void* theta_sketch_new(unsigned lg_k) {
}
}
+void* theta_sketch_new_lgk_p(unsigned lg_k, float p) {
+ try {
+ return new (palloc(sizeof(update_theta_sketch_pg)))
update_theta_sketch_pg(update_theta_sketch_pg::builder().set_lg_k(lg_k).set_p(p).build());
+ } catch (std::exception& e) {
+ elog(ERROR, e.what());
+ }
+}
+
void theta_sketch_delete(void* sketchptr) {
try {
static_cast<theta_sketch_pg*>(sketchptr)->~theta_sketch_pg();
diff --git a/src/theta_sketch_c_adapter.h b/src/theta_sketch_c_adapter.h
index 2082865..dfac5b4 100644
--- a/src/theta_sketch_c_adapter.h
+++ b/src/theta_sketch_c_adapter.h
@@ -11,7 +11,8 @@ extern "C" {
#endif
void* theta_sketch_new_default();
-void* theta_sketch_new(unsigned lg_k);
+void* theta_sketch_new_lgk(unsigned lg_k);
+void* theta_sketch_new_lgk_p(unsigned lg_k, float p);
void theta_sketch_delete(void* sketchptr);
void theta_sketch_update(void* sketchptr, const void* data, unsigned length);
diff --git a/src/theta_sketch_pg_functions.c b/src/theta_sketch_pg_functions.c
index d58b6bb..20c1e42 100644
--- a/src/theta_sketch_pg_functions.c
+++ b/src/theta_sketch_pg_functions.c
@@ -40,6 +40,7 @@ Datum pg_theta_sketch_a_not_b(PG_FUNCTION_ARGS);
Datum pg_theta_sketch_add_item(PG_FUNCTION_ARGS) {
void* sketchptr;
int lg_k;
+ float p;
// anyelement
Oid element_type;
@@ -64,7 +65,12 @@ Datum pg_theta_sketch_add_item(PG_FUNCTION_ARGS) {
if (PG_ARGISNULL(0)) {
lg_k = PG_GETARG_INT32(2);
- sketchptr = lg_k ? theta_sketch_new(lg_k) : theta_sketch_new_default();
+ p = PG_GETARG_FLOAT4(3);
+ if (lg_k) {
+ sketchptr = p ? theta_sketch_new_lgk_p(lg_k, p) :
theta_sketch_new_lgk(lg_k);
+ } else {
+ sketchptr = theta_sketch_new_default();
+ }
} else {
sketchptr = PG_GETARG_POINTER(0);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]