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 2024/08/30 19:09:18 UTC

(datasketches-bigquery) branch defaults_from_cpp created (now 633a389)

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a change to branch defaults_from_cpp
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git


      at 633a389  pass defaults from C++

This branch includes the following new commits:

     new 633a389  pass defaults from C++

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


(datasketches-bigquery) 01/01: pass defaults from C++

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch defaults_from_cpp
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git

commit 633a389b19dddea0dda85c491702fff823360ff6
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Fri Aug 30 12:08:45 2024 -0700

    pass defaults from C++
---
 cpc/cpc_sketch.cpp                                   | 3 +++
 cpc/sqlx/cpc_sketch_agg_string.sqlx                  | 4 ++--
 cpc/sqlx/cpc_sketch_agg_union.sqlx                   | 4 ++--
 cpc/sqlx/cpc_sketch_get_estimate.sqlx                | 2 +-
 cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx     | 2 +-
 cpc/sqlx/cpc_sketch_scalar_union.sqlx                | 2 +-
 cpc/sqlx/cpc_sketch_to_string.sqlx                   | 2 +-
 kll/kll_sketch.cpp                                   | 2 ++
 kll/sqlx/kll_sketch_float_build.sqlx                 | 2 +-
 kll/sqlx/kll_sketch_float_merge.sqlx                 | 2 +-
 theta/sqlx/theta_sketch_a_not_b.sqlx                 | 2 +-
 theta/sqlx/theta_sketch_agg_string.sqlx              | 4 ++--
 theta/sqlx/theta_sketch_agg_union.sqlx               | 4 ++--
 theta/sqlx/theta_sketch_get_estimate.sqlx            | 2 +-
 theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx | 2 +-
 theta/sqlx/theta_sketch_jaccard_similarity.sqlx      | 2 +-
 theta/sqlx/theta_sketch_scalar_intersection.sqlx     | 2 +-
 theta/sqlx/theta_sketch_scalar_union.sqlx            | 4 ++--
 theta/sqlx/theta_sketch_to_string.sqlx               | 2 +-
 theta/theta_sketch.cpp                               | 3 +++
 20 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/cpc/cpc_sketch.cpp b/cpc/cpc_sketch.cpp
index 4d5459f..fcb5eb8 100644
--- a/cpc/cpc_sketch.cpp
+++ b/cpc/cpc_sketch.cpp
@@ -33,6 +33,9 @@ EMSCRIPTEN_BINDINGS(cpc_sketch) {
     return std::string(reinterpret_cast<std::exception*>(ptr)->what());
   }));
 
+  emscripten::constant("DEFAULT_LG_K", datasketches::cpc_constants::DEFAULT_LG_K);
+  emscripten::constant("DEFAULT_SEED", datasketches::DEFAULT_SEED);
+
   emscripten::class_<datasketches::cpc_sketch>("cpc_sketch")
     .constructor(emscripten::optional_override([](uint8_t lg_k, uint64_t seed) {
       return new datasketches::cpc_sketch(lg_k, seed);
diff --git a/cpc/sqlx/cpc_sketch_agg_string.sqlx b/cpc/sqlx/cpc_sketch_agg_string.sqlx
index aca3dfa..5db3141 100644
--- a/cpc/sqlx/cpc_sketch_agg_string.sqlx
+++ b/cpc/sqlx/cpc_sketch_agg_string.sqlx
@@ -33,8 +33,8 @@ For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
 import ModuleFactory from "gs://$GCS_BUCKET/cpc_sketch.mjs";
 var Module = await ModuleFactory();
-const default_lg_k = Number(12);
-const default_seed = BigInt(9001);
+const default_lg_k = Number(Module.DEFAULT_LG_K);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 
 function destroyState(state) {
   if (state.sketch) {
diff --git a/cpc/sqlx/cpc_sketch_agg_union.sqlx b/cpc/sqlx/cpc_sketch_agg_union.sqlx
index fb89cd4..9b6c140 100644
--- a/cpc/sqlx/cpc_sketch_agg_union.sqlx
+++ b/cpc/sqlx/cpc_sketch_agg_union.sqlx
@@ -33,8 +33,8 @@ For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
 import ModuleFactory from "gs://$GCS_BUCKET/cpc_sketch.mjs";
 var Module = await ModuleFactory();
-const default_lg_k = Number(12);
-const default_seed = BigInt(9001);
+const default_lg_k = Number(Module.DEFAULT_LG_K);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 
 // ensures we have a union
 // if there is a serialized sketch, add it to the union and destroy it
diff --git a/cpc/sqlx/cpc_sketch_get_estimate.sqlx b/cpc/sqlx/cpc_sketch_get_estimate.sqlx
index 17a1d8a..c736da5 100644
--- a/cpc/sqlx/cpc_sketch_get_estimate.sqlx
+++ b/cpc/sqlx/cpc_sketch_get_estimate.sqlx
@@ -30,7 +30,7 @@ Param seed: This is used to confirm that the given sketch was configured with th
 Returns: a FLOAT64 value as the cardinality estimate.
 For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var sketch = Module.cpc_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx b/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx
index cc814fa..7795580 100644
--- a/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx
+++ b/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx
@@ -33,7 +33,7 @@ Param seed: This is used to confirm that the given sketch was configured with th
 Returns: an array of 3 FLOAT64 values as {estimate, lowerBound, upperBound}.
 For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var sketch = Module.cpc_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/cpc/sqlx/cpc_sketch_scalar_union.sqlx b/cpc/sqlx/cpc_sketch_scalar_union.sqlx
index 5c8afbf..7e736f9 100644
--- a/cpc/sqlx/cpc_sketch_scalar_union.sqlx
+++ b/cpc/sqlx/cpc_sketch_scalar_union.sqlx
@@ -33,7 +33,7 @@ Returns a CPC Sketch, as bytes, from which the union cardinality can be obtained
 For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
 const default_lg_k = 12;
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var union = new Module.cpc_union(lg_k ? lg_k : default_lg_k, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/cpc/sqlx/cpc_sketch_to_string.sqlx b/cpc/sqlx/cpc_sketch_to_string.sqlx
index 285de56..b11ffed 100644
--- a/cpc/sqlx/cpc_sketch_to_string.sqlx
+++ b/cpc/sqlx/cpc_sketch_to_string.sqlx
@@ -30,7 +30,7 @@ Param seed: This is used to confirm that the given sketch was configured with th
 Returns a string that represents the state of the given sketch.
 For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var sketch = Module.cpc_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/kll/kll_sketch.cpp b/kll/kll_sketch.cpp
index fe23f6b..01ffa6a 100644
--- a/kll/kll_sketch.cpp
+++ b/kll/kll_sketch.cpp
@@ -36,6 +36,8 @@ EMSCRIPTEN_BINDINGS(kll_sketch_float) {
   emscripten::register_vector<float>("VectorFloat");
   emscripten::register_vector<double>("VectorDouble");
 
+  emscripten::constant("DEFAULT_K", datasketches::kll_constants::DEFAULT_K);
+
   emscripten::class_<kll_sketch_float>("kll_sketch_float")
     .constructor(emscripten::optional_override([](uint16_t k) {
       return new kll_sketch_float(k);
diff --git a/kll/sqlx/kll_sketch_float_build.sqlx b/kll/sqlx/kll_sketch_float_build.sqlx
index 954d4a9..10d0324 100644
--- a/kll/sqlx/kll_sketch_float_build.sqlx
+++ b/kll/sqlx/kll_sketch_float_build.sqlx
@@ -32,7 +32,7 @@ For more details: https://datasketches.apache.org/docs/KLL/KLLSketch.html'''
 ) AS R"""
 import ModuleFactory from "gs://$GCS_BUCKET/kll_sketch.mjs";
 var Module = await ModuleFactory();
-const default_k = Number(200);
+const default_k = Number(Module.DEFAULT_K);
 
 // UDAF interface
 export function initialState(k) {
diff --git a/kll/sqlx/kll_sketch_float_merge.sqlx b/kll/sqlx/kll_sketch_float_merge.sqlx
index 32ce25a..6da379a 100644
--- a/kll/sqlx/kll_sketch_float_merge.sqlx
+++ b/kll/sqlx/kll_sketch_float_merge.sqlx
@@ -32,7 +32,7 @@ For more details: https://datasketches.apache.org/docs/KLL/KLLSketch.html'''
 ) AS R"""
 import ModuleFactory from "gs://$GCS_BUCKET/kll_sketch.mjs";
 var Module = await ModuleFactory();
-const default_k = Number(200);
+const default_k = Number(Module.DEFAULT_K);
 
 // UDAF interface
 export function initialState(k) {
diff --git a/theta/sqlx/theta_sketch_a_not_b.sqlx b/theta/sqlx/theta_sketch_a_not_b.sqlx
index ed15962..2f50067 100644
--- a/theta/sqlx/theta_sketch_a_not_b.sqlx
+++ b/theta/sqlx/theta_sketch_a_not_b.sqlx
@@ -31,7 +31,7 @@ Param seed: This is used to confirm that the given sketches were configured with
 Returns: a Compact, Compressed Theta Sketch, as bytes, from which the set difference cardinality can be obtained.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var a_not_b = new Module.theta_a_not_b(seed ? BigInt(seed) : default_seed);
   try {
diff --git a/theta/sqlx/theta_sketch_agg_string.sqlx b/theta/sqlx/theta_sketch_agg_string.sqlx
index f67dec2..013942b 100644
--- a/theta/sqlx/theta_sketch_agg_string.sqlx
+++ b/theta/sqlx/theta_sketch_agg_string.sqlx
@@ -33,8 +33,8 @@ For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramewor
 ) AS R"""
 import ModuleFactory from "gs://$GCS_BUCKET/theta_sketch.mjs";
 var Module = await ModuleFactory();
-const default_lg_k = Number(12);
-const default_seed = BigInt(9001);
+const default_lg_k = Number(Module.DEFAULT_LG_K);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 
 function destroyState(state) {
   if (state.sketch) {
diff --git a/theta/sqlx/theta_sketch_agg_union.sqlx b/theta/sqlx/theta_sketch_agg_union.sqlx
index ca9b774..023c1a8 100644
--- a/theta/sqlx/theta_sketch_agg_union.sqlx
+++ b/theta/sqlx/theta_sketch_agg_union.sqlx
@@ -33,8 +33,8 @@ For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramewor
 ) AS R"""
 import ModuleFactory from "gs://$GCS_BUCKET/theta_sketch.mjs";
 var Module = await ModuleFactory();
-const default_lg_k = Number(12);
-const default_seed = BigInt(9001);
+const default_lg_k = Number(Module.DEFAULT_LG_K);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 
 var buffer = {ptr: 0, size: 0};
 
diff --git a/theta/sqlx/theta_sketch_get_estimate.sqlx b/theta/sqlx/theta_sketch_get_estimate.sqlx
index 56af06c..4afeb20 100644
--- a/theta/sqlx/theta_sketch_get_estimate.sqlx
+++ b/theta/sqlx/theta_sketch_get_estimate.sqlx
@@ -30,7 +30,7 @@ Param seed: This is used to confirm that the given sketch was configured with th
 Returns: a FLOAT64 value as the cardinality estimate.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var sketch = Module.compact_theta_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx b/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx
index 987b976..0ab9e0d 100644
--- a/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx
+++ b/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx
@@ -33,7 +33,7 @@ Param seed: This is used to confirm that the given sketch was configured with th
 Returns: an array of 3 FLOAT64 values as {estimate, lowerBound, upperBound}.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var sketch = Module.compact_theta_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/theta/sqlx/theta_sketch_jaccard_similarity.sqlx b/theta/sqlx/theta_sketch_jaccard_similarity.sqlx
index 50f5c48..b69a33f 100644
--- a/theta/sqlx/theta_sketch_jaccard_similarity.sqlx
+++ b/theta/sqlx/theta_sketch_jaccard_similarity.sqlx
@@ -34,7 +34,7 @@ Param seed: This is used to confirm that the given sketches were configured with
 Returns: an array of 3 floating-point values {LowerBound, Estimate, UpperBound} of the Jaccard index.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   const jaccard = Module.thetaJaccardSimilarity(sketchA, sketchB, seed == null ? default_seed : BigInt(seed));
   return [jaccard.get(0), jaccard.get(1), jaccard.get(2)];
diff --git a/theta/sqlx/theta_sketch_scalar_intersection.sqlx b/theta/sqlx/theta_sketch_scalar_intersection.sqlx
index dfa3b4a..cdc15e9 100644
--- a/theta/sqlx/theta_sketch_scalar_intersection.sqlx
+++ b/theta/sqlx/theta_sketch_scalar_intersection.sqlx
@@ -31,7 +31,7 @@ Param seed: This is used to confirm that the given sketches were configured with
 Returns: a Compact, Compressed Theta Sketch, as bytes, from which the intersection cardinality can be obtained.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var intersection = new Module.theta_intersection(seed ? BigInt(seed) : default_seed);
   try {
diff --git a/theta/sqlx/theta_sketch_scalar_union.sqlx b/theta/sqlx/theta_sketch_scalar_union.sqlx
index 45855a3..6c13f09 100644
--- a/theta/sqlx/theta_sketch_scalar_union.sqlx
+++ b/theta/sqlx/theta_sketch_scalar_union.sqlx
@@ -32,8 +32,8 @@ Param seed: This is used to confirm that the given sketches were configured with
 Returns: a Compact, Compressed Theta Sketch, as bytes, from which the union cardinality can be obtained.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_lg_k = 12;
-const default_seed = BigInt(9001);
+const default_lg_k = Number(Module.DEFAULT_LG_K);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var union = new Module.theta_union(lg_k ? lg_k : default_lg_k, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/theta/sqlx/theta_sketch_to_string.sqlx b/theta/sqlx/theta_sketch_to_string.sqlx
index f81f3ba..57eecd1 100644
--- a/theta/sqlx/theta_sketch_to_string.sqlx
+++ b/theta/sqlx/theta_sketch_to_string.sqlx
@@ -30,7 +30,7 @@ Param seed: This is used to confirm that the given sketch was configured with th
 Returns: a string that represents the state of the given sketch.
 For more details: https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
-const default_seed = BigInt(9001);
+const default_seed = BigInt(Module.DEFAULT_SEED);
 try {
   var sketch = Module.compact_theta_sketch.deserializeFromB64(sketch, seed ? BigInt(seed) : default_seed);
   try {
diff --git a/theta/theta_sketch.cpp b/theta/theta_sketch.cpp
index 5dbee41..86fb5b8 100644
--- a/theta/theta_sketch.cpp
+++ b/theta/theta_sketch.cpp
@@ -44,6 +44,9 @@ EMSCRIPTEN_BINDINGS(theta_sketch) {
     return std::string(reinterpret_cast<std::exception*>(ptr)->what());
   }));
 
+  emscripten::constant("DEFAULT_LG_K", datasketches::theta_constants::DEFAULT_LG_K);
+  emscripten::constant("DEFAULT_SEED", datasketches::DEFAULT_SEED);
+
   emscripten::class_<update_theta_sketch>("update_theta_sketch")
     .constructor(emscripten::optional_override([](uint8_t lg_k) {
       return new update_theta_sketch(update_theta_sketch::builder().set_lg_k(lg_k).build());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org