Jackie-Jiang commented on code in PR #16605:
URL: https://github.com/apache/pinot/pull/16605#discussion_r2279944739


##########
pinot-core/src/main/java/org/apache/pinot/core/operator/query/NonScanBasedAggregationOperator.java:
##########
@@ -291,6 +326,30 @@ private static Object 
getDistinctCountSmartHLLResult(Dictionary dictionary,
     }
   }
 
+  private static UltraLogLog getDistinctCountULLResult(Dictionary dictionary, 
int p) {
+    return getDistinctValueULL(dictionary, p);
+  }
+
+  private static UltraLogLog 
getDistinctCountULLMergedFromBytesDictionary(Dictionary dictionary) {
+    // Treat BYTES value as serialized ULL and merge
+    UltraLogLog ull = 
UltraLogLog.create(org.apache.pinot.spi.utils.CommonConstants.Helix.DEFAULT_ULTRALOGLOG_P);

Review Comment:
   (minor) Fix the import, same for other places



##########
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountSmartULLAggregationFunction.java:
##########
@@ -0,0 +1,1067 @@
+/**
+ * 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.dynatrace.hash4j.distinctcount.UltraLogLog;
+import com.google.common.base.Preconditions;
+import it.unimi.dsi.fastutil.doubles.DoubleOpenHashSet;
+import it.unimi.dsi.fastutil.floats.FloatOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+import it.unimi.dsi.fastutil.objects.ObjectSet;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.pinot.common.CustomObject;
+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.local.utils.UltraLogLogUtils;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+import org.apache.pinot.segment.spi.index.reader.Dictionary;
+import org.apache.pinot.spi.data.FieldSpec.DataType;
+import org.apache.pinot.spi.utils.ByteArray;
+import org.roaringbitmap.PeekableIntIterator;
+import org.roaringbitmap.RoaringBitmap;
+
+
+/**
+ * The {@code DistinctCountSmartULLAggregationFunction} calculates the number 
of distinct values for a given expression
+ * (both single-valued and multi-valued are supported).
+ *
+ * For aggregation-only queries, the distinct values are stored in a Set 
initially. Once the number of distinct values
+ * exceeds a threshold, the Set will be converted into an UltraLogLog, and 
approximate result will be returned.
+ *
+ * The function takes an optional second argument for parameters:
+ * - threshold: Threshold of the number of distinct values to trigger the 
conversion, 100_000 by default. Non-positive
+ *              value means never convert.
+ * - p: Parameter p for UltraLogLog, default defined by 
CommonConstants.Helix.DEFAULT_ULTRALOGLOG_P.
+ * Example of second argument: 'threshold=10;p=16'
+ */
+@SuppressWarnings({"rawtypes", "unchecked"})
+public class DistinctCountSmartULLAggregationFunction extends 
BaseSingleInputAggregationFunction<Object, Integer> {

Review Comment:
   Ideally we should make this and DistinctCountSmartHLL share the same base 
class for raw value handling. Maybe add a TODO



##########
pinot-core/src/main/java/org/apache/pinot/core/operator/query/NonScanBasedAggregationOperator.java:
##########
@@ -144,6 +148,27 @@ protected AggregationResultsBlock getNextBlock() {
           result = 
getDistinctCountSmartHLLResult(Objects.requireNonNull(dataSource.getDictionary()),
               (DistinctCountSmartHLLAggregationFunction) aggregationFunction);
           break;
+        case DISTINCTCOUNTULL:
+          result = 
getDistinctCountULLResult(Objects.requireNonNull(dataSource.getDictionary()),
+              ((DistinctCountULLAggregationFunction) aggregationFunction)
+                  .getP());
+          break;
+        case DISTINCTCOUNTSMARTULL:
+          result = 
getDistinctCountSmartULLResult(Objects.requireNonNull(dataSource.getDictionary()),
+              (DistinctCountSmartULLAggregationFunction) aggregationFunction);
+          break;
+        case DISTINCTCOUNTRAWULL: {
+          Dictionary dictionary = 
Objects.requireNonNull(dataSource.getDictionary());
+          int p =
+              ((DistinctCountULLAggregationFunction) aggregationFunction)
+                  .getP();
+          if (dictionary.getValueType() == FieldSpec.DataType.BYTES) {

Review Comment:
   Why do we need to specialize BYTES type here? It should be the same as 
DISTINCTOUNSMARTHLL



-- 
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]

Reply via email to