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 5054044  cpc sketch to string
5054044 is described below

commit 5054044f5f8fd6ddb1b9797591d4195386189df9
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Mon Aug 5 18:08:06 2024 -0700

    cpc sketch to string
---
 cpc_sketch_to_string.sql | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/cpc_sketch_to_string.sql b/cpc_sketch_to_string.sql
new file mode 100644
index 0000000..d2c5bc2
--- /dev/null
+++ b/cpc_sketch_to_string.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_to_string(base64 BYTES, seed INT64) 
RETURNS STRING 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.toString();
+  } 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