xiangfu0 commented on code in PR #18229: URL: https://github.com/apache/pinot/pull/18229#discussion_r3212585504
########## 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: Updated in current head b162190b67: this is now directly covered for both cases. CodecPipelineValidator rejects CODEC(DELTA,DELTA,LZ4) and CODEC(DELTA,DELTADELTA,LZ4), with CodecPipelineValidatorTest.testDuplicateDeltaRejected and testDeltaAndDeltaDeltaBothRejected locking the behavior. -- 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]
