You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "xiangfu0 (via GitHub)" <gi...@apache.org> on 2026/04/16 12:08:31 UTC

Re: [PR] Add codec pipeline framework for raw forward index encoding [pinot]

xiangfu0 commented on code in PR #18229:
URL: https://github.com/apache/pinot/pull/18229#discussion_r3093045410


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/io/codec/CodecPipelineValidator.java:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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.util.List;
+import org.apache.pinot.segment.spi.codec.CodecContext;
+import org.apache.pinot.segment.spi.codec.CodecDefinition;
+import org.apache.pinot.segment.spi.codec.CodecInvocation;
+import org.apache.pinot.segment.spi.codec.CodecKind;
+import org.apache.pinot.segment.spi.codec.CodecOptions;
+import org.apache.pinot.segment.spi.codec.CodecPipeline;
+
+
+/**
+ * Validates a {@link CodecPipeline} against structural rules and per-codec context.
+ *
+ * <p>Rules enforced:
+ * <ol>
+ *   <li>All codec names must be registered in the supplied {@link CodecRegistry}.</li>
+ *   <li>At most one {@link CodecKind#COMPRESSION} stage is allowed.</li>
+ *   <li>The compression stage, if present, must be last.</li>
+ *   <li>All {@link CodecKind#TRANSFORM} stages must precede the compression stage.</li>
+ *   <li>Each codec's {@link CodecDefinition#validateContext} must pass.</li>
+ * </ol>
+ */
+public final class CodecPipelineValidator {
+
+  private CodecPipelineValidator() {
+  }
+
+  /**
+   * Validates the pipeline.
+   *
+   * @param pipeline pipeline AST to validate
+   * @param registry registry used to resolve codec names
+   * @param ctx      column context for type validation
+   * @throws IllegalArgumentException if any validation rule is violated
+   */
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  public static void validate(CodecPipeline pipeline, CodecRegistry registry, CodecContext ctx) {
+    List<CodecInvocation> stages = pipeline.stages();
+
+    int compressionCount = 0;
+    int compressionIndex = -1;
+
+    for (int i = 0; i < stages.size(); i++) {
+      CodecInvocation invocation = stages.get(i);
+      CodecDefinition codec = registry.getOrThrow(invocation.name());
+      CodecOptions options = codec.parseOptions(invocation.args());
+      codec.validateContext(options, ctx);
+
+      if (codec.kind() == CodecKind.COMPRESSION) {
+        compressionCount++;

Review Comment:
   This only counts compression stages. The executor collapses transform stages into booleans, so `CODEC(DELTA,DELTA)` would pass validation, get encoded as a single delta layer, and then be decoded once, silently corrupting values. Please reject duplicate transform stages here or preserve the full ordered stage list in the executor.



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

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


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