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

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


The following commit(s) were added to refs/heads/main by this push:
     new 976290c  cpc estimate and bounds
976290c is described below

commit 976290ce59b8da0d0e497ce94e241d9c3e4c7738
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Mon Aug 5 18:29:54 2024 -0700

    cpc estimate and bounds
---
 cpc_sketch_get_estimate_and_bounds.sql | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/cpc_sketch_get_estimate_and_bounds.sql 
b/cpc_sketch_get_estimate_and_bounds.sql
new file mode 100644
index 0000000..37fccb8
--- /dev/null
+++ b/cpc_sketch_get_estimate_and_bounds.sql
@@ -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.
+
+CREATE OR REPLACE FUNCTION 
`$BQ_PROJECT.$BQ_DATASET`.cpc_sketch_get_estimate_and_bounds(base64 BYTES, 
num_std_devs INT, seed INT64) RETURNS ARRAY<FLOAT64> LANGUAGE js
+OPTIONS (library=["gs://$GCS_BUCKET/cpc_sketch.js"]) AS R"""
+const default_seed = BigInt(9001);
+try {
+  var sketch = Module.cpc_sketch.deserializeFromB64(base64, seed ? 
BigInt(seed) : default_seed);
+  try {
+    return [sketch.getEstimate(), sketch.getLowerBound(num_std_devs), 
sketch.getUpperBound(num_std_devs)];
+  } finally {
+    sketch.delete();
+  }
+} 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