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 2019/08/19 17:27:04 UTC
[incubator-datasketches-postgresql] branch cpc_init created (now
537173f)
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a change to branch cpc_init
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-postgresql.git.
at 537173f cpc init and cleanup
This branch includes the following new commits:
new 537173f cpc init and cleanup
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
[incubator-datasketches-postgresql] 01/01: cpc init and cleanup
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch cpc_init
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-postgresql.git
commit 537173f28c2985b32a6bf1bc360c928c3038fd75
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Mon Aug 19 10:26:32 2019 -0700
cpc init and cleanup
---
Makefile | 3 ++-
src/cpc_sketch_c_adapter.cpp | 11 ++++++++---
src/cpc_sketch_c_adapter.h | 3 +++
src/global_hooks.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index f73b17c..84435b4 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ DATA = $(SQL_INSTALL)
EXTRA_CLEAN = $(SQL_INSTALL)
-OBJS = src/base64.o src/common.o \
+OBJS = src/global_hooks.o src/base64.o src/common.o \
src/kll_float_sketch_pg_functions.o src/kll_float_sketch_c_adapter.o \
src/cpc_sketch_pg_functions.o src/cpc_sketch_c_adapter.o \
src/theta_sketch_pg_functions.o src/theta_sketch_c_adapter.o \
@@ -17,6 +17,7 @@ OBJS = src/base64.o src/common.o \
# assume a copy or link datasketches-cpp in the current dir
CORE = datasketches-cpp
+
CPC = $(CORE)/cpc/src
OBJS += $(CPC)/cpc_sketch.o $(CPC)/fm85.o $(CPC)/fm85Compression.o $(CPC)/fm85Confidence.o $(CPC)/fm85Merging.o $(CPC)/fm85Util.o $(CPC)/iconEstimator.o $(CPC)/u32Table.o
diff --git a/src/cpc_sketch_c_adapter.cpp b/src/cpc_sketch_c_adapter.cpp
index d6d4520..35de712 100644
--- a/src/cpc_sketch_c_adapter.cpp
+++ b/src/cpc_sketch_c_adapter.cpp
@@ -24,9 +24,16 @@
#include <cpc_sketch.hpp>
#include <cpc_union.hpp>
+void cpc_init() {
+ datasketches::cpc_init(&palloc, &pfree);
+}
+
+void cpc_cleanup() {
+ datasketches::cpc_cleanup();
+}
+
void* cpc_sketch_new(unsigned lg_k) {
try {
- datasketches::cpc_init(&palloc, &pfree);
return new (palloc(sizeof(datasketches::cpc_sketch))) datasketches::cpc_sketch(lg_k, datasketches::DEFAULT_SEED);
} catch (std::exception& e) {
elog(ERROR, "%s", e.what());
@@ -94,7 +101,6 @@ void* cpc_sketch_serialize(const void* sketchptr) {
void* cpc_sketch_deserialize(const char* buffer, unsigned length) {
try {
- datasketches::cpc_init(&palloc, &pfree);
auto ptr = datasketches::cpc_sketch::deserialize(buffer, length, datasketches::DEFAULT_SEED);
return ptr.release();
} catch (std::exception& e) {
@@ -104,7 +110,6 @@ void* cpc_sketch_deserialize(const char* buffer, unsigned length) {
void* cpc_union_new(unsigned lg_k) {
try {
- datasketches::cpc_init(&palloc, &pfree);
return new (palloc(sizeof(datasketches::cpc_union))) datasketches::cpc_union(lg_k, datasketches::DEFAULT_SEED);
} catch (std::exception& e) {
elog(ERROR, "%s", e.what());
diff --git a/src/cpc_sketch_c_adapter.h b/src/cpc_sketch_c_adapter.h
index 962040e..91683ef 100644
--- a/src/cpc_sketch_c_adapter.h
+++ b/src/cpc_sketch_c_adapter.h
@@ -26,6 +26,9 @@ extern "C" {
#include <postgres.h>
+void cpc_init();
+void cpc_cleanup();
+
void* cpc_sketch_new(unsigned lg_k);
void cpc_sketch_delete(void* sketchptr);
diff --git a/src/global_hooks.c b/src/global_hooks.c
new file mode 100644
index 0000000..7f8d529
--- /dev/null
+++ b/src/global_hooks.c
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// PostgreSQL hooks to execute on loading and unloading
+// CPC sketch needs global initialization of compression tables
+
+#include "cpc_sketch_c_adapter.h"
+
+void _PG_init() {
+ cpc_init();
+}
+
+void _PG_fini() {
+ cpc_cleanup();
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org