cbalci commented on code in PR #11774: URL: https://github.com/apache/pinot/pull/11774#discussion_r1353024718
########## pinot-core/src/main/java/org/apache/pinot/core/common/ObjectSerDeUtils.java: ########## @@ -515,23 +518,23 @@ public VarianceTuple deserialize(ByteBuffer byteBuffer) { } }; - public static final ObjectSerDe<PinotFourthMoment> PINOT_FOURTH_MOMENT_OBJECT_SER_DE - = new ObjectSerDe<PinotFourthMoment>() { - @Override - public byte[] serialize(PinotFourthMoment value) { - return value.serialize(); - } + public static final ObjectSerDe<PinotFourthMoment> PINOT_FOURTH_MOMENT_OBJECT_SER_DE = + new ObjectSerDe<PinotFourthMoment>() { + @Override + public byte[] serialize(PinotFourthMoment value) { + return value.serialize(); + } - @Override - public PinotFourthMoment deserialize(byte[] bytes) { - return PinotFourthMoment.fromBytes(bytes); - } + @Override + public PinotFourthMoment deserialize(byte[] bytes) { + return PinotFourthMoment.fromBytes(bytes); + } - @Override - public PinotFourthMoment deserialize(ByteBuffer byteBuffer) { - return PinotFourthMoment.fromBytes(byteBuffer); - } - }; + @Override + public PinotFourthMoment deserialize(ByteBuffer byteBuffer) { + return PinotFourthMoment.fromBytes(byteBuffer); + } + }; Review Comment: Do we need these formatting changes? They don't look relevant to the PR ########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountCPCAggregationFunction.java: ########## @@ -0,0 +1,358 @@ +/** + * 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.cpc.CpcSketch; +import org.apache.datasketches.cpc.CpcUnion; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.utils.DataSchema; +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; +import org.apache.pinot.spi.data.FieldSpec.DataType; +import org.apache.pinot.spi.utils.CommonConstants; + + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class DistinctCountCPCAggregationFunction extends BaseSingleInputAggregationFunction<CpcSketch, Comparable> { Review Comment: Please add some docstring which documents the usage and behavior. ########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/DistinctCountRawCPCAggregationFunction.java: ########## @@ -0,0 +1,53 @@ +/** + * 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 java.util.Base64; +import java.util.List; +import org.apache.datasketches.cpc.CpcSketch; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.utils.DataSchema.ColumnDataType; +import org.apache.pinot.segment.spi.AggregationFunctionType; + + +/** + * The {@code DistinctCountRawCPCAggregationFunction} shares the same usage as the + * {@link DistinctCountCPCAggregationFunction}, and returns the sketch as a base64 encoded string. + */ +public class DistinctCountRawCPCAggregationFunction extends DistinctCountCPCAggregationFunction { + + public DistinctCountRawCPCAggregationFunction(List<ExpressionContext> arguments) { + super(arguments); + } + + @Override + public AggregationFunctionType getType() { + return AggregationFunctionType.DISTINCTCOUNTRAWCPCSKETCH; + } + + @Override + public ColumnDataType getFinalResultColumnType() { + return ColumnDataType.STRING; + } + + @Override + public String extractFinalResult(CpcSketch sketch) { + return Base64.getEncoder().encodeToString(sketch.toByteArray()); + } Review Comment: Would be nice to return a serialized CPC sketch object here which has a custom `compareTo` implementation. Something like: https://github.com/apache/pinot/blob/master/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/customobject/SerializedKLL.java -- 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