justahuman1 commented on code in PR #18088: URL: https://github.com/apache/pinot/pull/18088#discussion_r3105492429
########## pinot-core/src/main/java/org/apache/pinot/core/segment/processing/aggregator/PercentileTDigestAggregator.java: ########## @@ -0,0 +1,63 @@ +/** + * 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.segment.processing.aggregator; + +import com.tdunning.math.stats.TDigest; +import java.util.Map; +import org.apache.pinot.core.common.ObjectSerDeUtils; +import org.apache.pinot.core.query.aggregation.function.PercentileTDigestAggregationFunction; +import org.apache.pinot.segment.spi.Constants; + + +public class PercentileTDigestAggregator implements ValueAggregator { + + @Override + public Object aggregate(Object value1, Object value2, Map<String, String> functionParameters) { + byte[] bytes1 = (byte[]) value1; + byte[] bytes2 = (byte[]) value2; + + // Empty byte arrays represent the default null value for BYTES columns. + // Deserializing byte[0] would throw BufferUnderflowException, so handle it explicitly. + if (bytes1.length == 0 && bytes2.length == 0) { + int compression = getCompression(functionParameters); + return ObjectSerDeUtils.TDIGEST_SER_DE.serialize(TDigest.createMergingDigest(compression)); Review Comment: Thanks for the patience @Jackie-Jiang—was waiting for tests/builds to finish and also wanted to think this through. Updated this PR to treat empty bytes as missing in `PercentileTDigestAggregator` (returns empty bytes now). On extending this to the query-time aggregation functions (TDigest, HLL, ThetaSketch, KLL, etc. — only CPC currently handles empty bytes per [#17925](https://github.com/apache/pinot/pull/17925)): I've been discussing internally and there's a real tradeoff worth flagging. The recent HLL incident on our side was actually caught *because* queries crashed on empty bytes from a stripped `defaultNullValue` — if it had silently returned 0, the misconfiguration wouldn't have surfaced. Some considerations of our team's was that users should be intentional about setting `defaultNullValue` for BYTES columns. That said, silent null-handling is still probably saner client-facing behavior in most cases, and extending CPC's pattern is a reasonable cleanup. Agree it should be a separate PR — want to think through the tradeoff more (and probably add metrics so silent nulls aren't invisible) before picking it up. **Let me know if you're in favor of adding this null handling throughout T-Digest (and potentially other sketches) and I will send it out in a separate PR.** -- 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]
