@@ -0,0 +1,2276 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.facebook.presto.tests;%0A%0Aimport com.facebook.presto.sql.planner.LogicalPlanner;%0Aimport com.facebook.presto.sql.planner.Plan;%0Aimport com.facebook.presto.sql.planner.PlanPrinter;%0Aimport com.facebook.presto.testing.LocalQueryRunner;%0A%0Aimport java.util.function.Function;%0Aimport java.util.stream.IntStream;%0A%0Aimport static org.testng.Assert.assertEquals;%0A%0Apublic class PlanDeterminismChecker%0A%7B%0A    private static final int MINIMUM_SUBSEQUENT_SAME_PLANS = 10;%0A%0A    private final LocalQueryRunner localQueryRunner;%0A    private final Function%3CString, String%3E planEquivalenceFunction;%0A%0A    public PlanDeterminismChecker(LocalQueryRunner localQueryRunner)%0A    %7B%0A        this(localQueryRunner, Function.identity());%0A    %7D%0A%0A    public PlanDeterminismChecker(LocalQueryRunner localQueryRunner, Function%3CString, String%3E planEquivalenceFunction)%0A    %7B%0A        this.localQueryRunner = localQueryRunner;%0A        this.planEquivalenceFunction = planEquivalenceFunction;%0A    %7D%0A%0A    public void checkPlanIsDeterministic(String sql)%0A    %7B%0A        IntStream.range(1, MINIMUM_SUBSEQUENT_SAME_PLANS)%0A                .mapToObj(attempt -%3E getPlanText(sql))%0A                .map(planEquivalenceFunction)%0A                .reduce((previous, current) -%3E %7B%0A                    assertEquals(previous, current);%0A                    return current;%0A                %7D);%0A    %7D%0A%0A    private String getPlanText(String sql)%0A    %7B%0A        return localQueryRunner.inTransaction(session -%3E %7B%0A            Plan plan = localQueryRunner.createPlan(session, sql, LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED);%0A            return PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), localQueryRunner.getMetadata(), session);%0A        %7D);%0A    %7D%0A%7D%0A

Add PlanDeterminismChecker