yashmayya commented on code in PR #14702:
URL: https://github.com/apache/pinot/pull/14702#discussion_r1900573674
##########
pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/Constants.java:
##########
@@ -32,4 +32,5 @@ private Constants() {
public static final String THETA_TUPLE_SKETCH_NOMINAL_ENTRIES =
"nominalEntries";
public static final String PERCENTILETDIGEST_COMPRESSION_FACTOR_KEY =
"compressionFactor";
public static final String SUMPRECISION_PRECISION_KEY = "precision";
+ public static final String KLL_DOUBLE_SKETCH_K_VALUE = "kValue";
Review Comment:
Maybe we can simply call this `K` as that's what DataSketches seems to use -
https://datasketches.apache.org/docs/KLL/KLLAccuracyAndSize.html#:~:?
##########
pinot-core/src/main/java/org/apache/pinot/core/segment/processing/aggregator/PercentileKLLSketchAggregator.java:
##########
@@ -0,0 +1,70 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.core.segment.processing.aggregator;
+
+import java.util.Map;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.kll.KllDoublesSketch;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * Class to merge KLL doubles sketch for minion merge/rollup tasks.
+ */
+public class PercentileKLLSketchAggregator implements ValueAggregator {
+
+ protected static final int DEFAULT_K_VALUE = 200;
+
+ /**
+ * Given two kll doubles sketches, return the aggregated kll doubles sketches
+ * @return aggregated sketch given two kll doubles sketches
+ */
+ @Override
+ public Object aggregate(Object value1, Object value2, Map<String, String>
functionParameters) {
+ try {
+ String kValueParam =
functionParameters.get(Constants.KLL_DOUBLE_SKETCH_K_VALUE);
+
+ int sketchKValue;
+
+ // Check if nominal entries values match
+ if (kValueParam != null) {
+ sketchKValue = Integer.parseInt(kValueParam);
+ } else {
+ // If the functionParameters don't have an explicit K value set,
+ // use the default value for K
Review Comment:
nit: can be a single line comment, the max line length is 120.
##########
pinot-core/src/main/java/org/apache/pinot/core/segment/processing/aggregator/PercentileKLLSketchAggregator.java:
##########
@@ -0,0 +1,70 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.core.segment.processing.aggregator;
+
+import java.util.Map;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.kll.KllDoublesSketch;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * Class to merge KLL doubles sketch for minion merge/rollup tasks.
+ */
+public class PercentileKLLSketchAggregator implements ValueAggregator {
+
+ protected static final int DEFAULT_K_VALUE = 200;
Review Comment:
Can be removed here as you've added `DEFAULT_KLL_SKETCH_K` to the Helix
common constants.
##########
pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java:
##########
@@ -129,6 +129,10 @@ public static class Helix {
public static final int DEFAULT_CPC_SKETCH_LGK = 12;
public static final int DEFAULT_ULTRALOGLOG_P = 12;
+ // K is set to 200, for tradeoffs see datasketches library documentation:
+ // https://datasketches.apache.org/docs/KLL/KLLAccuracyAndSize.html#:~:
+ public static final int DEFAULT_KLL_SKETCH_K = 200;
+
Review Comment:
Can you also update `PercentileKLLAggregationFunction` to use this default
and remove the duplicate default from there?
##########
pinot-core/src/main/java/org/apache/pinot/core/segment/processing/aggregator/PercentileKLLSketchAggregator.java:
##########
@@ -0,0 +1,70 @@
+/**
+ * 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.
+ */
+package org.apache.pinot.core.segment.processing.aggregator;
+
+import java.util.Map;
+import org.apache.datasketches.common.SketchesArgumentException;
+import org.apache.datasketches.kll.KllDoublesSketch;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.segment.spi.Constants;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+/**
+ * Class to merge KLL doubles sketch for minion merge/rollup tasks.
+ */
+public class PercentileKLLSketchAggregator implements ValueAggregator {
+
+ protected static final int DEFAULT_K_VALUE = 200;
+
+ /**
+ * Given two kll doubles sketches, return the aggregated kll doubles sketches
+ * @return aggregated sketch given two kll doubles sketches
+ */
+ @Override
+ public Object aggregate(Object value1, Object value2, Map<String, String>
functionParameters) {
+ try {
+ String kValueParam =
functionParameters.get(Constants.KLL_DOUBLE_SKETCH_K_VALUE);
+
+ int sketchKValue;
+
+ // Check if nominal entries values match
+ if (kValueParam != null) {
+ sketchKValue = Integer.parseInt(kValueParam);
+ } else {
+ // If the functionParameters don't have an explicit K value set,
+ // use the default value for K
+ sketchKValue = CommonConstants.Helix.DEFAULT_KLL_SKETCH_K;
+ }
+
+ KllDoublesSketch first =
ObjectSerDeUtils.KLL_SKETCH_SER_DE.deserialize((byte[]) value1);
+ KllDoublesSketch second =
ObjectSerDeUtils.KLL_SKETCH_SER_DE.deserialize((byte[]) value2);
+ KllDoublesSketch union = KllDoublesSketch.newHeapInstance(sketchKValue);
+ if (first != null) {
+ union.merge(first);
+ }
+ if (second != null) {
+ union.merge(second);
+ }
Review Comment:
When would these values be `null`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]