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

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

commit 20f14980fc42e5e61d1db3b77cfb90a49e2b6aa0
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Wed Sep 4 13:57:03 2024 -0700

    better return type
---
 cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx     | 10 +++++++---
 hll/sqlx/hll_sketch_get_estimate_and_bounds.sqlx     | 10 +++++++---
 theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx | 10 +++++++---
 theta/sqlx/theta_sketch_jaccard_similarity.sqlx      | 10 +++++++---
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx 
b/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx
index 56e85a5..5e96373 100644
--- a/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx
+++ b/cpc/sqlx/cpc_sketch_get_estimate_and_bounds.sqlx
@@ -20,7 +20,7 @@
 config { hasOutput: true }
 
 CREATE OR REPLACE FUNCTION ${self()}(sketch BYTES, num_std_devs BYTEINT, seed 
INT64)
-RETURNS ARRAY<FLOAT64>
+RETURNS STRUCT<estimate FLOAT64, lower_bound FLOAT64, upper_bound FLOAT64>
 LANGUAGE js
 OPTIONS (
   library=["gs://$GCS_BUCKET/cpc_sketch.js"],
@@ -30,14 +30,18 @@ Param num_std_devs: The returned bounds will be based on 
the statistical confide
 from the returned estimate. This number may be one of {1,2,3}, where 1 
represents 68% confidence, 2 represents 95% confidence and 3 represents 99.7% 
confidence.
 For example, if the given num_std_devs = 2 and the returned values are {1000, 
990, 1010} that means that with 95% confidence, the true value lies within the 
range [990, 1010].
 Param seed: This is used to confirm that the given sketch was configured with 
the correct seed.
-Returns: an array of 3 FLOAT64 values as {estimate, lowerBound, upperBound}.
+Returns: a struct with 3 FLOAT64 values as {estimate, lower_bound, 
upper_bound}.
 For more details: https://datasketches.apache.org/docs/CPC/CPC.html'''
 ) AS R"""
 try {
   var sketchObject = null;
   try {
     sketchObject = Module.cpc_sketch.deserializeFromB64(sketch, seed ? 
BigInt(seed) : BigInt(Module.DEFAULT_SEED));
-    return [sketchObject.getEstimate(), 
sketchObject.getLowerBound(num_std_devs), 
sketchObject.getUpperBound(num_std_devs)];
+    return {
+      estimate: sketchObject.getEstimate(),
+      lower_bound: sketchObject.getLowerBound(num_std_devs),
+      upper_bound: sketchObject.getUpperBound(num_std_devs)
+    };
   } finally {
     if (sketchObject != null) sketchObject.delete();
   }
diff --git a/hll/sqlx/hll_sketch_get_estimate_and_bounds.sqlx 
b/hll/sqlx/hll_sketch_get_estimate_and_bounds.sqlx
index 99d3d53..02fc9ff 100644
--- a/hll/sqlx/hll_sketch_get_estimate_and_bounds.sqlx
+++ b/hll/sqlx/hll_sketch_get_estimate_and_bounds.sqlx
@@ -20,7 +20,7 @@
 config { hasOutput: true }
 
 CREATE OR REPLACE FUNCTION ${self()}(sketch BYTES, num_std_devs BYTEINT)
-RETURNS ARRAY<FLOAT64>
+RETURNS STRUCT<estimate FLOAT64, lower_bound FLOAT64, upper_bound FLOAT64>
 LANGUAGE js
 OPTIONS (
   library=["gs://$GCS_BUCKET/hll_sketch.js"],
@@ -29,14 +29,18 @@ Param sketch: The given sketch to query as bytes.
 Param num_std_devs: The returned bounds will be based on the statistical 
confidence interval determined by the given number of standard deviations
 from the returned estimate. This number may be one of {1,2,3}, where 1 
represents 68% confidence, 2 represents 95% confidence and 3 represents 99.7% 
confidence.
 For example, if the given num_std_devs = 2 and the returned values are {1000, 
990, 1010} that means that with 95% confidence, the true value lies within the 
range [990, 1010].
-Returns: an array of 3 FLOAT64 values as {estimate, lowerBound, upperBound}.
+Returns: a struct with 3 FLOAT64 values as {estimate, lower_bound, 
upper_bound}.
 For more details: https://datasketches.apache.org/docs/HLL/HLL.html'''
 ) AS R"""
 try {
   var sketchObject = null;
   try {
     sketchObject = Module.hll_sketch.deserializeFromB64(sketch);
-    return [sketchObject.getEstimate(), 
sketchObject.getLowerBound(num_std_devs), 
sketchObject.getUpperBound(num_std_devs)];
+    return {
+      estimate: sketchObject.getEstimate(),
+      lower_bound: sketchObject.getLowerBound(num_std_devs),
+      upper_bound: sketchObject.getUpperBound(num_std_devs)
+    };
   } finally {
     if (sketchObject != null) sketchObject.delete();
   }
diff --git a/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx 
b/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx
index 1f80b4f..0929a25 100644
--- a/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx
+++ b/theta/sqlx/theta_sketch_get_estimate_and_bounds.sqlx
@@ -20,7 +20,7 @@
 config { hasOutput: true }
 
 CREATE OR REPLACE FUNCTION ${self()}(sketch BYTES, num_std_devs BYTEINT, seed 
INT64)
-RETURNS ARRAY<FLOAT64>
+RETURNS STRUCT<estimate FLOAT64, lower_bound FLOAT64, upper_bound FLOAT64>
 LANGUAGE js
 OPTIONS (
   library=["gs://$GCS_BUCKET/theta_sketch.js"],
@@ -30,7 +30,7 @@ Param num_std_devs: The returned bounds will be based on the 
statistical confide
 from the returned estimate. This number may be one of {1,2,3}, where 1 
represents 68% confidence, 2 represents 95% confidence and 3 represents 99.7% 
confidence.
 For example, if the given num_std_devs = 2 and the returned values are {1000, 
990, 1010} that means that with 95% confidence, the true value lies within the 
range [990, 1010].
 Param seed: This is used to confirm that the given sketch was configured with 
the correct seed.
-Returns: an array of 3 FLOAT64 values as {estimate, lowerBound, upperBound}.
+Returns: a struct with 3 FLOAT64 values as {estimate, lower_bound, 
upper_bound}.
 For more details: 
https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
 const default_seed = BigInt(Module.DEFAULT_SEED);
@@ -38,7 +38,11 @@ try {
   var sketchObject = null;
   try {
     sketchObject = Module.compact_theta_sketch.deserializeFromB64(sketch, seed 
? BigInt(seed) : default_seed);
-    return [sketchObject.getEstimate(), 
sketchObject.getLowerBound(num_std_devs), 
sketchObject.getUpperBound(num_std_devs)];
+    return {
+      estimate: sketchObject.getEstimate(),
+      lower_bound: sketchObject.getLowerBound(num_std_devs),
+      upper_bound: sketchObject.getUpperBound(num_std_devs)
+    };
   } finally {
     if (sketchObject != null) sketchObject.delete();
   }
diff --git a/theta/sqlx/theta_sketch_jaccard_similarity.sqlx 
b/theta/sqlx/theta_sketch_jaccard_similarity.sqlx
index b69a33f..0ba0c86 100644
--- a/theta/sqlx/theta_sketch_jaccard_similarity.sqlx
+++ b/theta/sqlx/theta_sketch_jaccard_similarity.sqlx
@@ -20,7 +20,7 @@
 config { hasOutput: true }
 
 CREATE OR REPLACE FUNCTION ${self()}(sketchA BYTES, sketchB BYTES, seed INT64)
-RETURNS ARRAY<FLOAT64>
+RETURNS STRUCT<lower_bound FLOAT64, estimate FLOAT64, upper_bound FLOAT64>
 LANGUAGE js
 OPTIONS (
   library=["gs://$GCS_BUCKET/theta_sketch.js"],
@@ -31,13 +31,17 @@ A Jaccard of .95 means the overlap between the two sets is 
95% of the union of t
 Param sketchA: the first sketch as bytes.
 Param sketchB: the second sketch as bytes.
 Param seed: This is used to confirm that the given sketches were configured 
with the correct seed.
-Returns: an array of 3 floating-point values {LowerBound, Estimate, 
UpperBound} of the Jaccard index.
+Returns: a struct with 3 floating-point values {lower_bound, estimate, 
upper_bound} of the Jaccard index.
 For more details: 
https://datasketches.apache.org/docs/Theta/ThetaSketchFramework.html'''
 ) AS R"""
 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)];
+  return {
+    lower_bound: jaccard.get(0),
+    estimate: jaccard.get(1),
+    upper_bound: jaccard.get(2)
+  };
 } catch (e) {
   throw new Error(Module.getExceptionMessage(e));
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to