xiangfu0 commented on code in PR #19305: URL: https://github.com/apache/pinot/pull/19305#discussion_r3856049591
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/io/codec/DeltaDeltaCodecDefinition.java: ########## @@ -0,0 +1,209 @@ +/** + * 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.io.codec; + +import java.nio.ByteBuffer; +import java.util.List; + + +/// Transform codec that computes delta-of-delta values between successive values before the +/// compression stage (if any). Useful for data where the differences between consecutive values +/// are approximately constant (e.g. timestamps with regular intervals). +/// +/// DSL form: `DELTADELTA` (no arguments) +/// +/// Supported stored types: `INT`, `LONG`. +/// +/// Stateless and thread-safe; the [#INSTANCE] singleton is shared across all columns. +/// +/// Wire format (header-less passthrough — element type from the column context, value count from +/// the buffer length, so the output is a same-width typed value array a following transform can +/// consume): +/// ``` +/// [element_size bytes: first value verbatim] +/// [element_size bytes: first delta (second - first), if count > 1] +/// [(count-2) * element_size bytes: delta-of-deltas, if count > 2] +/// ``` +final class DeltaDeltaCodecDefinition Review Comment: They are close but not interchangeable, so we kept both — `DELTA,DELTA` stays legal in the DSL (the validator accepts chained value-preserving transforms), while `DELTADELTA` is the dedicated form. Trade-offs: **Not the same encoding at index 1.** `DELTADELTA` emits `[v0, v1−v0, second differences…]` (the classic Gorilla-style form). Composing `DELTA` twice emits `[v0, (v1−v0)−v0, second differences…]` — the second slot carries an epoch-magnitude outlier for timestamp columns. Both round-trip exactly, but when a frame-of-reference packing stage follows (`DELTADELTA,T64,…`), that one outlier forces max bit-width for the whole first 64-value block; the dedicated codec keeps every post-`v0` value small. **Cost per stage.** The executor runs each stage as a full pass with its own intermediate buffer, so `DELTA,DELTA` is two passes + one extra scratch buffer per chunk on encode *and* decode; `DELTADELTA` does the second difference in a single pass. **Frozen-name surface (the real argument for dropping it).** Codec names are permanent on-disk contracts once V7 headers ship. Dropping `DELTADELTA` later would be a format break, whereas adding it later would have been compatible — so keeping it is a commitment. We think it earns it as the canonical transform for the headline use case (near-regular timestamps), but if you prefer to minimize the frozen surface, removing it from the registry in this PR and re-adding it later is fully backward-compatible — happy to do that instead. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_ -- 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]
