xiangfu0 commented on code in PR #18996: URL: https://github.com/apache/pinot/pull/18996#discussion_r3594210060
########## pinot-core/src/main/java/org/apache/pinot/core/query/aggregation/function/PercentileTDigestAccumulator.java: ########## @@ -0,0 +1,448 @@ +/** + * 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.MergingDigest; +import com.tdunning.math.stats.TDigest; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.util.Arrays; + +/// Accumulates raw values and serialized TDigests into centroids without repeatedly sorting existing centroids. +/// +/// The accumulator is used while a percentile TDigest result, or one of its group-by results, is being built. Raw +/// values are sorted in small batches, while serialized TDigest centroids are decoded in their existing sorted order. +/// Both are linearly merged with the accumulated centroids and compressed using the same weight-limit rule as +/// [MergingDigest]. [#toTDigest()] normalizes the result to a standard [MergingDigest], so intermediate-result +/// serialization and distributed merging remain unchanged. +/// +/// Serialized group state keeps its first digest pending, and allocates primitive centroid buffers only when another +/// input must be merged. The raw-value buffer remains unallocated for serialized state until a raw value is added. +/// +/// Instances are thread-confined to one aggregation result or group-by result. +final class PercentileTDigestAccumulator { Review Comment: Follow-up in b7b01bd667: the reducer-specific optimization now makes PercentileTDigestAccumulator extend TDigest, so process-local IndexedTable reduction and distributed deserialization retain primitive centroid state. The public/wire representation is still canonical TDigest 3.2 bytes, and serialized group state keeps both centroid buffers and the raw-value buffer lazy until needed. -- 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]
