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



##########
File path: 
pinot-common/src/test/java/org/apache/pinot/common/function/AggregationFunctionTypeTest.java
##########
@@ -48,6 +48,12 @@ public void testGetAggregationFunctionType() {
         AggregationFunctionType.PERCENTILEEST);
     
Assert.assertEquals(AggregationFunctionType.getAggregationFunctionType("PeRcEnTiLeTdIgEsT99"),
         AggregationFunctionType.PERCENTILETDIGEST);
+    Assert

Review comment:
       The code format seems incorrect

##########
File path: 
pinot-core/src/test/java/org/apache/pinot/queries/SerializedBytesQueriesTest.java
##########
@@ -94,7 +94,7 @@
   // Use non-default compression
   private static final double PERCENTILE_TDIGEST_COMPRESSION = 200;
   // Allow 5% quantile error due to the randomness of TDigest merge
-  private static final double PERCENTILE_TDIGEST_DELTA = 0.05 * 
Integer.MAX_VALUE;
+  public static final double PERCENTILE_TDIGEST_DELTA = 0.05 * 
Integer.MAX_VALUE;

Review comment:
       Don't expose this value outside of this test

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/customobject/SerializedQuantileDigest.java
##########
@@ -0,0 +1,49 @@
+/**
+ * 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.segment.local.customobject;
+
+import org.apache.pinot.segment.local.utils.CustomSerDeUtils;
+import org.apache.pinot.spi.utils.BytesUtils;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Serialized and comparable version of QuantileDigest. Compares 
QuantileDigest for a specific percentile value.
+ */
+public class SerializedQuantileDigest implements 
Comparable<SerializedQuantileDigest> {
+  private final double _percentile;
+  private final QuantileDigest _quantileDigest;
+
+  public SerializedQuantileDigest(QuantileDigest quantileDigest, double 
percentile) {
+    _quantileDigest = quantileDigest;
+    _percentile = percentile;
+  }
+
+  @Override
+  public int compareTo(SerializedQuantileDigest other) {
+    checkArgument(other._percentile == _percentile, "Percentile number doesn't 
match!");
+    return Double.compare(_quantileDigest.getQuantile(_percentile / 100.0),
+        other._quantileDigest.getQuantile(_percentile / 100.0));
+  }
+
+  @Override
+  public String toString() {
+    return 
BytesUtils.toHexString(CustomSerDeUtils.QUANTILE_DIGEST_SER_DE.serialize(_quantileDigest));
+  }
+}

Review comment:
       (nit) new line

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/customobject/SerializedTDigest.java
##########
@@ -0,0 +1,49 @@
+/**
+ * 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.segment.local.customobject;
+
+import com.tdunning.math.stats.TDigest;
+import org.apache.pinot.segment.local.utils.CustomSerDeUtils;
+import org.apache.pinot.spi.utils.BytesUtils;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Serialized and comparable version of TDigest. Compares TDigest for a 
specific percentile value.
+ */
+public class SerializedTDigest implements Comparable<SerializedTDigest> {
+  private final double _percentile;
+  private final TDigest _tDigest;
+
+  public SerializedTDigest(TDigest tDigest, double percentile) {
+    _tDigest = tDigest;
+    _percentile = percentile;

Review comment:
       Same

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/customobject/SerializedQuantileDigest.java
##########
@@ -0,0 +1,49 @@
+/**
+ * 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.segment.local.customobject;
+
+import org.apache.pinot.segment.local.utils.CustomSerDeUtils;
+import org.apache.pinot.spi.utils.BytesUtils;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Serialized and comparable version of QuantileDigest. Compares 
QuantileDigest for a specific percentile value.
+ */
+public class SerializedQuantileDigest implements 
Comparable<SerializedQuantileDigest> {
+  private final double _percentile;
+  private final QuantileDigest _quantileDigest;
+
+  public SerializedQuantileDigest(QuantileDigest quantileDigest, double 
percentile) {
+    _quantileDigest = quantileDigest;
+    _percentile = percentile;

Review comment:
       Directly save `percentile / 100.0` to avoid repeating computation in 
`compareTo`

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/customobject/SerializedQuantileDigest.java
##########
@@ -0,0 +1,49 @@
+/**
+ * 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.segment.local.customobject;
+
+import org.apache.pinot.segment.local.utils.CustomSerDeUtils;
+import org.apache.pinot.spi.utils.BytesUtils;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Serialized and comparable version of QuantileDigest. Compares 
QuantileDigest for a specific percentile value.
+ */
+public class SerializedQuantileDigest implements 
Comparable<SerializedQuantileDigest> {
+  private final double _percentile;
+  private final QuantileDigest _quantileDigest;
+
+  public SerializedQuantileDigest(QuantileDigest quantileDigest, double 
percentile) {
+    _quantileDigest = quantileDigest;
+    _percentile = percentile;
+  }
+
+  @Override
+  public int compareTo(SerializedQuantileDigest other) {
+    checkArgument(other._percentile == _percentile, "Percentile number doesn't 
match!");
+    return Double.compare(_quantileDigest.getQuantile(_percentile / 100.0),

Review comment:
       Use `Long.compare`

##########
File path: 
pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/PercentileRawTDigestAggregationFunction.java
##########
@@ -0,0 +1,142 @@
+/**
+ * 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.tdunning.math.stats.TDigest;
+import java.util.Map;
+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.query.aggregation.AggregationResultHolder;
+import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder;
+import org.apache.pinot.segment.local.utils.CustomSerDeUtils;
+import org.apache.pinot.segment.spi.AggregationFunctionType;
+import org.apache.pinot.spi.utils.BytesUtils;
+
+
+/**
+ * The {@code PercentileRawTDigestAggregationFunction} returns the serialized 
{@code TDigest} data structure of the
+ * {@code PercentileEstAggregationFunction}.
+ */
+public class PercentileRawTDigestAggregationFunction extends 
BaseSingleInputAggregationFunction<TDigest, String> {
+  private final PercentileTDigestAggregationFunction 
_percentileRawTDigestAggregationFunction;
+
+  public PercentileRawTDigestAggregationFunction(ExpressionContext 
expressionContext, int percentile) {
+    this(expressionContext, new 
PercentileTDigestAggregationFunction(expressionContext, percentile));
+  }
+
+  public PercentileRawTDigestAggregationFunction(ExpressionContext 
expressionContext, double percentile) {
+    this(expressionContext, new 
PercentileTDigestAggregationFunction(expressionContext, percentile));
+  }
+
+  protected PercentileRawTDigestAggregationFunction(ExpressionContext 
expression,
+      PercentileTDigestAggregationFunction 
percentileRawTDigestAggregationFunction) {

Review comment:
       Still not correct




-- 
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-unsubscr...@pinot.apache.org

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



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

Reply via email to