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/23 05:38:16 UTC
(datasketches-bigquery) 01/01: hll get estimate and bounds
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch hll
in repository https://gitbox.apache.org/repos/asf/datasketches-bigquery.git
commit 3b5697e0c03663499e80cf29faa4356853be8bc3
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Thu Aug 22 22:37:52 2024 -0700
hll get estimate and bounds
---
hll/sqxl/hll_sketch_get_estimate_and_bounds.sqlx | 46 ++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/hll/sqxl/hll_sketch_get_estimate_and_bounds.sqlx b/hll/sqxl/hll_sketch_get_estimate_and_bounds.sqlx
new file mode 100644
index 0000000..99d3d53
--- /dev/null
+++ b/hll/sqxl/hll_sketch_get_estimate_and_bounds.sqlx
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+config { hasOutput: true }
+
+CREATE OR REPLACE FUNCTION ${self()}(sketch BYTES, num_std_devs BYTEINT)
+RETURNS ARRAY<FLOAT64>
+LANGUAGE js
+OPTIONS (
+ library=["gs://$GCS_BUCKET/hll_sketch.js"],
+ description = '''Gets cardinality estimate and bounds from given sketch.
+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}.
+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)];
+ } finally {
+ if (sketchObject != null) sketchObject.delete();
+ }
+} catch (e) {
+ throw new Error(Module.getExceptionMessage(e));
+}
+""";
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org