github-actions[bot] commented on code in PR #68871: URL: https://github.com/apache/doris/pull/68871#discussion_r4244197593
########## fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/physical/PhysicalPlanVisitorDispatchTest.java: ########## @@ -0,0 +1,181 @@ +// 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.doris.nereids.trees.plans.physical; + +import org.apache.doris.nereids.trees.plans.Plan; +import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Consistency check of the physical plan visitor dispatch. + * + * <p>Every plan node that implements {@code accept()} itself hard codes the {@code visitXxx} method of + * {@link PlanVisitor} that handles it. When such a node has a dedicated hook in {@link PlanVisitor}, + * the dispatch has to reach that hook: dispatching to a parent type silently turns the dedicated hook + * into unreachable dead code, and nothing catches it - the compiler is happy and no runtime test fails. + * + * <p>The check reads the invoked method out of the compiled {@code accept()} body, so it covers every + * physical plan node instead of a hand picked one. Nodes that inherit {@code accept()} from a parent + * plan are out of scope by construction. + */ +public class PhysicalPlanVisitorDispatchTest { + + /** Guards against the class path scan silently finding nothing and making this test vacuous. */ + private static final int MIN_CHECKED_PLAN_CLASSES = 30; + + private static final String PLAN_PACKAGE = "org.apache.doris.nereids.trees.plans.physical"; + + private static final String ACCEPT_DESCRIPTOR = + "(Lorg/apache/doris/nereids/trees/plans/visitor/PlanVisitor;Ljava/lang/Object;)Ljava/lang/Object;"; + + @Test + public void acceptDispatchesToItsOwnMostSpecificVisitorMethod() throws Exception { + Path classesRoot = classesRoot(); + Path packageRoot = classesRoot.resolve(PLAN_PACKAGE.replace('.', '/')); + List<String> violations = new ArrayList<>(); + int checked = 0; + + for (Path classFile : planClassFiles(packageRoot)) { + Class<?> planClass = Class.forName(toClassName(packageRoot, classFile), false, + PhysicalPlanVisitorDispatchTest.class.getClassLoader()); + if (!Plan.class.isAssignableFrom(planClass) || Modifier.isAbstract(planClass.getModifiers()) + || !declaresAccept(planClass)) { + continue; + } + String dispatched = dispatchedVisitorMethod(classFile); + if (dispatched == null) { Review Comment: [P2] Fail when a declared accept has no unambiguous visitor call. If `PhysicalLazyMaterializeTVFScan.accept()` stops dispatching (or invokes two `visit*` methods), `dispatchedVisitorMethod` returns null and this branch silently skips it. The other 44 concrete direct accept methods still exceed the 30-class floor, so this regression test passes even though the exact dispatch fixed by this PR is broken. Record this as a violation, and assert that the TVF class was checked. -- 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]
