You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/09/01 18:28:07 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #7383: Add HLLSketch and HLLPlusPlus aggregate functions

Jackie-Jiang commented on a change in pull request #7383:
URL: https://github.com/apache/pinot/pull/7383#discussion_r700459971



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountHLLSketchAggregationFunction.java
##########
@@ -0,0 +1,363 @@
+/**
+ * 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.query.aggregation.function;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import org.apache.datasketches.hll.HllSketch;
+import org.apache.datasketches.hll.TgtHllType;
+import org.apache.datasketches.hll.Union;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.utils.DataSchema.ColumnDataType;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.common.ObjectSerDeUtils;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.ObjectAggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.ObjectGroupByResultHolder;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+
+public class DistinctCountHLLSketchAggregationFunction extends BaseSingleInputAggregationFunction<HllSketch, Long> {
+  // This is log-base2 of k, so k = 4096. lgK can be from 4 to 21
+  protected final int _log2k;
+  protected final TgtHllType _tgtHllType;
+
+  public DistinctCountHLLSketchAggregationFunction(List<ExpressionContext> arguments) {
+    super(arguments.get(0));
+    int numExpressions = arguments.size();
+    // This function expects 1 or 2 arguments.
+    Preconditions
+        .checkArgument(numExpressions <= 2, "DistinctCountHLLSketch expects 1 or 2 arguments, got: %s", numExpressions);
+    if (arguments.size() == 2) {
+      _log2k = Integer.parseInt(arguments.get(1).getLiteral());
+    } else {
+      _log2k = CommonConstants.Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K;
+    }
+    _tgtHllType = HllSketch.DEFAULT_HLL_TYPE;

Review comment:
       This seems a constant?

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountHLLPlusPlusMVAggregationFunction.java
##########
@@ -0,0 +1,225 @@
+/**
+ * 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.query.aggregation.function;
+
+import com.clearspring.analytics.stream.cardinality.HyperLogLogPlus;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.core.common.BlockValSet;
+import org.apache.pinot.core.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+
+
+public class DistinctCountHLLPlusPlusMVAggregationFunction extends DistinctCountHLLPlusPlusAggregationFunction {

Review comment:
       Let's use one function to support both SV and MV. You may refer to `DistinctCountThetaSketchAggregationFunction` on how to support both SV and MV in one function

##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
##########
@@ -79,6 +79,18 @@ private CommonConstants() {
     public static final String DEFAULT_HYPERLOGLOG_LOG2M_KEY = "default.hyperloglog.log2m";
     public static final int DEFAULT_HYPERLOGLOG_LOG2M = 8;
 
+    public static final String DEFAULT_HYPERLOGLOGPLUSPLUS_NORMAL_PRECISION_KEY =
+        "default.hyperloglogplusplus.normal.precision";
+    /** The default normal precision that is used if the user does not specify a normal precision. */
+    public static final int DEFAULT_HYPERLOGLOGPLUSPLUS_NORMAL_PRECISION = 15;
+
+    public static final String DEFAULT_HYPERLOGLOGPLUSPLUS_SPARSE_PRECISION_KEY =
+        "default.hyperloglogplusplus.sparse.precision";
+    public static final int DEFAULT_HYPERLOGLOGPLUSPLUS_SPARSE_PRECISION = 20;
+
+    public static final String DEFAULT_HYPERLOGLOG_SKETCH_LOG2K_KEY = "default.hyperloglogsketch.log2k";

Review comment:
       (nit) 
   ```suggestion
       public static final String DEFAULT_HYPERLOGLOGSKETCH_LOG2K_KEY = "default.hyperloglogsketch.log2k";
   ```

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/BaseBrokerStarter.java
##########
@@ -219,6 +219,40 @@ public void start()
       }
     }
 
+    String log2kStr = configMap.get(Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K);

Review comment:
       ```suggestion
       String log2kStr = configMap.get(Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K_KEY);
   ```

##########
File path: pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/BaseBrokerStarter.java
##########
@@ -219,6 +219,40 @@ public void start()
       }
     }
 
+    String log2kStr = configMap.get(Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K);
+    if (log2kStr != null) {
+      try {
+        _brokerConf.setProperty(Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K_KEY, Integer.parseInt(log2kStr));
+      } catch (NumberFormatException e) {
+        LOGGER.warn("Invalid config of '{}': '{}', using: {} as the default log2k for HllSketch",
+            Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY, log2kStr, Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K);

Review comment:
       ```suggestion
               Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2M_KEY, log2kStr, Helix.DEFAULT_HYPERLOGLOG_SKETCH_LOG2K);
   ```




-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org