alex-plekhanov commented on code in PR #13068: URL: https://github.com/apache/ignite/pull/13068#discussion_r3267589311
########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { Review Comment: It's not a planner test, it's an integration test, you almost not use AbstractPlannerTest except `plannerCtx`, but you don't need it, the same result can be obtained by just: ``` sql("EXPLAIN PLAN FOR " + loadFromResource(sqlTestName(getClass()) + "/" + queryId + ".sql")) ``` So, it's more correct to inherit from `AbstractBasicIntegrationTest` ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; + + /** Run once, before all queries check. */ + @BeforePlansTest + public static void startAll(Class<?> testClass) throws Exception { + AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest(); + + mock.beforeFirstTest(); + + IgniteConfiguration cfg = mock.getConfiguration("server"); + + cfg.getSqlConfiguration() + .setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)); + + srv = (IgniteEx)IgnitionEx.start(cfg); + + srv.getOrCreateCache(new CacheConfiguration<>("mock") + .setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class) + .setSqlSchema("PUBLIC")); + + TpchHelper.createTables(srv); + +/* + TpchHelper.fillTables(srv, 0.01); + + TpchHelper.collectSqlStatistics(srv); +*/ + } + + /** Run once, after all queries check. */ + @AfterPlansTest + public static void stopAll(Class<?> testClass) { + if (srv != null) { + srv.close(); + + srv = null; + } + } + + /** Test single query. */ + @Test + public void testQuery() throws Exception { + String actualPlan = queryPlan(); + + if (UPDATE_PLAN) { + updatePlan(actualPlan); + + return; + } + + PlanTemplate pt = new PlanTemplate(loadFromResource(String.format("%s/%s.plan", sqlTestName(getClass()), queryId))); + + if (!pt.match(actualPlan)) { + // This assertion will print nice diff in IDE that will help to investigate. + // Test will fail anyway. + assertEquals(pt.template, actualPlan); + + assert false : "Should not happen"; + } + } + + /** {@inheritDoc} */ + @Override protected boolean isSafeTopology() { + return false; + } + + /** */ + private String queryPlan() throws Exception { + Map<String, IgniteSchema> schemas = GridTestUtils.getFieldValue( + ((CalciteQueryProcessor)srv.context().query().defaultQueryEngine()).schemaHolder(), + "igniteSchemas" + ); + + PlanningContext ctx = plannerCtx(loadFromResource(sqlTestName(getClass()) + "/" + queryId + ".sql"), schemas.values(), null); + + return new PlanTemplate(RelOptUtil.toString(physicalPlan(ctx), SqlExplainLevel.ALL_ATTRIBUTES)).template; + } + + /** */ + private void updatePlan(String newPlan) { + Path targetDir = Path.of(RSRC_DIR + sqlTestName(getClass())); + + // A targetDirectory must be specified by hand when expected plans are generated. + if (targetDir == null) { + throw new RuntimeException("Please provide target directory to where save generated plans." + + " Usually plans are kept in resource folder of tests within the same module."); + } + + try { + Files.createDirectories(targetDir); + + Files.writeString(targetDir.resolve(String.format("%s.plan", queryId)), newPlan); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Execute SQL query. + * + * @param ignite Ignite. + * @param sql SQL query. + * @param params Query parameters. + */ + public static List<List<?>> sql(Ignite ignite, String sql, Object... params) { + SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(params); + + try (FieldsQueryCursor<List<?>> cur = ((IgniteEx)ignite).context().query().querySqlFields(qry, false)) { + return cur.getAll(); + } + } + + /** */ + public static class TpchUDF { + /** */ + @QuerySqlFunction(alias = "SUBSTR") + public static String substr(String str, int from, int cnt) { + return str.substring(from, from + cnt); + } + } + + /** + * Loads resource with given name as string. + * + * @param resource Name of the resource to load. + * @return Resource as string. + */ + private static String loadFromResource(String resource) { Review Comment: Abbreviation should be used ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanTemplate.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Contains logic to process plans templates. + * Supported templates: + * <ul> + * <li>{@code ", id = 123} replaced with the {@code ", id = {id}}</li> + * <li>{@code ", hash=123} replaced with the {@code ", hash={hash}}</li> + * <li>{@code "{INDEX_CASE:IDX1,IDX2}} expands to the plans where {INDEX_CASE....} replaced with each of the index from list.</li> + * <li>{@code "{ONEOF}} start and finish with the {@code {ONEOF}} tag. Cases separated with the line "=====". + * Creates as many plans as there are cases. + * </li> + * </ul> + */ +public class PlanTemplate { + /** */ + private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+"); + + /** */ + private static final Pattern HASH_PATTERN = Pattern.compile(", hash=-?\\d+]"); + + /** */ + public final String template; + + /** */ + public PlanTemplate(String template) { + this.template = HASH_PATTERN.matcher(ID_PATTERN.matcher(template) + .replaceAll(", id = {id}")) + .replaceAll(", hash={hash}"); + } + + /** + * @param actualPlan Plan to match. + * @return {@code True} if any expanded plan equals to the parameter. + */ + public boolean match(String actualPlan) { + return expandOneof(template).stream() + .flatMap(PlanTemplate::expandIndexCase) + .anyMatch(possiblePlan -> possiblePlan.equals(actualPlan)); + } + + /** Expands plans. Replace {INDEX_CASE} tag with the possible indexes. */ + private static Stream<String> expandIndexCase(String plan) { + List<String> res = new ArrayList<>(); + + res.add(plan); + + while (true) { + String idxCaseStart = "{INDEX_CASE:"; + + if (res.get(0).contains(idxCaseStart)) { + res = res.stream().flatMap(p -> { + int start = p.indexOf(idxCaseStart); + int end = p.indexOf('}', start); + + assert start != -1 && end != -1; + + String[] idxs = p.substring(start + idxCaseStart.length(), end).split(","); + + return Arrays.stream(idxs).map(idx -> p.substring(0, start) + idx + p.substring(end + 1)); + }).collect(Collectors.toList()); + } + else + break; + } + + return res.stream(); + } + + /** Expands plans. Replace {ONEOF} tag with the possible cases. */ + private static List<String> expandOneof(String plan) { Review Comment: `Oneof` -> `OneOf` Inconsistent API with `expandIndexCase` (one returns Stream, another returns List) ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; + + /** Run once, before all queries check. */ + @BeforePlansTest + public static void startAll(Class<?> testClass) throws Exception { + AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest(); + + mock.beforeFirstTest(); + + IgniteConfiguration cfg = mock.getConfiguration("server"); + + cfg.getSqlConfiguration() + .setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)); + + srv = (IgniteEx)IgnitionEx.start(cfg); + + srv.getOrCreateCache(new CacheConfiguration<>("mock") + .setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class) + .setSqlSchema("PUBLIC")); + + TpchHelper.createTables(srv); + +/* + TpchHelper.fillTables(srv, 0.01); + + TpchHelper.collectSqlStatistics(srv); +*/ + } + + /** Run once, after all queries check. */ + @AfterPlansTest + public static void stopAll(Class<?> testClass) { + if (srv != null) { + srv.close(); + + srv = null; + } + } Review Comment: Overcomplicated, it's hard to read and understand. All `PlanChecker` related code (together with PlanChecker itself) can be replaced with standard parameterized test, all you need is one method: ``` @Parameterized.Parameters(name = "queryId={0}") public static Collection<String> params() throws IOException { return Files.list(Path.of(RSRC_DIR, "tpch")) .filter(p -> p.toString().endsWith(".sql") && !p.toString().endsWith("ddl.sql")) .sorted() .map(p -> p.getFileName().toString().replace(".sql", "")) .collect(Collectors.toList()); } ``` Or extend `AbstractTpchTest` and redefine set of tests. ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; Review Comment: Abbreviation should be used ########## modules/calcite/src/test/resources/tpch/variant_q12.sql: ########## @@ -0,0 +1,25 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +-- This variant replaces the CASE statement from the Functional Query Definition with equivalent DECODE() syntax Review Comment: Why do we need all these variants? DECODE is replaced with CASE before planing, on validation. Plan not affected by this replacement. Why do we need both variants? ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; + + /** Run once, before all queries check. */ + @BeforePlansTest + public static void startAll(Class<?> testClass) throws Exception { + AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest(); + + mock.beforeFirstTest(); + + IgniteConfiguration cfg = mock.getConfiguration("server"); + + cfg.getSqlConfiguration() + .setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)); + + srv = (IgniteEx)IgnitionEx.start(cfg); + + srv.getOrCreateCache(new CacheConfiguration<>("mock") + .setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class) + .setSqlSchema("PUBLIC")); + + TpchHelper.createTables(srv); + +/* + TpchHelper.fillTables(srv, 0.01); + + TpchHelper.collectSqlStatistics(srv); +*/ + } + + /** Run once, after all queries check. */ + @AfterPlansTest + public static void stopAll(Class<?> testClass) { + if (srv != null) { + srv.close(); + + srv = null; + } + } + + /** Test single query. */ + @Test + public void testQuery() throws Exception { + String actualPlan = queryPlan(); + + if (UPDATE_PLAN) { + updatePlan(actualPlan); + + return; + } + + PlanTemplate pt = new PlanTemplate(loadFromResource(String.format("%s/%s.plan", sqlTestName(getClass()), queryId))); + + if (!pt.match(actualPlan)) { + // This assertion will print nice diff in IDE that will help to investigate. + // Test will fail anyway. + assertEquals(pt.template, actualPlan); + + assert false : "Should not happen"; + } + } + + /** {@inheritDoc} */ + @Override protected boolean isSafeTopology() { + return false; + } + + /** */ + private String queryPlan() throws Exception { + Map<String, IgniteSchema> schemas = GridTestUtils.getFieldValue( + ((CalciteQueryProcessor)srv.context().query().defaultQueryEngine()).schemaHolder(), + "igniteSchemas" + ); + + PlanningContext ctx = plannerCtx(loadFromResource(sqlTestName(getClass()) + "/" + queryId + ".sql"), schemas.values(), null); + + return new PlanTemplate(RelOptUtil.toString(physicalPlan(ctx), SqlExplainLevel.ALL_ATTRIBUTES)).template; + } + + /** */ + private void updatePlan(String newPlan) { + Path targetDir = Path.of(RSRC_DIR + sqlTestName(getClass())); + + // A targetDirectory must be specified by hand when expected plans are generated. + if (targetDir == null) { + throw new RuntimeException("Please provide target directory to where save generated plans." + + " Usually plans are kept in resource folder of tests within the same module."); + } + + try { + Files.createDirectories(targetDir); + + Files.writeString(targetDir.resolve(String.format("%s.plan", queryId)), newPlan); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Execute SQL query. + * + * @param ignite Ignite. + * @param sql SQL query. + * @param params Query parameters. + */ + public static List<List<?>> sql(Ignite ignite, String sql, Object... params) { Review Comment: Not needed if test will be inherited from `AbstractBasicIntegrationTest` ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; + + /** Run once, before all queries check. */ + @BeforePlansTest + public static void startAll(Class<?> testClass) throws Exception { + AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest(); + + mock.beforeFirstTest(); + + IgniteConfiguration cfg = mock.getConfiguration("server"); + + cfg.getSqlConfiguration() + .setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)); + + srv = (IgniteEx)IgnitionEx.start(cfg); + + srv.getOrCreateCache(new CacheConfiguration<>("mock") + .setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class) + .setSqlSchema("PUBLIC")); + + TpchHelper.createTables(srv); + +/* + TpchHelper.fillTables(srv, 0.01); + + TpchHelper.collectSqlStatistics(srv); +*/ + } + + /** Run once, after all queries check. */ + @AfterPlansTest + public static void stopAll(Class<?> testClass) { + if (srv != null) { + srv.close(); + + srv = null; + } + } + + /** Test single query. */ + @Test + public void testQuery() throws Exception { + String actualPlan = queryPlan(); + + if (UPDATE_PLAN) { + updatePlan(actualPlan); + + return; + } + + PlanTemplate pt = new PlanTemplate(loadFromResource(String.format("%s/%s.plan", sqlTestName(getClass()), queryId))); + + if (!pt.match(actualPlan)) { + // This assertion will print nice diff in IDE that will help to investigate. + // Test will fail anyway. + assertEquals(pt.template, actualPlan); + + assert false : "Should not happen"; + } + } + + /** {@inheritDoc} */ + @Override protected boolean isSafeTopology() { + return false; + } + + /** */ + private String queryPlan() throws Exception { + Map<String, IgniteSchema> schemas = GridTestUtils.getFieldValue( + ((CalciteQueryProcessor)srv.context().query().defaultQueryEngine()).schemaHolder(), + "igniteSchemas" + ); + + PlanningContext ctx = plannerCtx(loadFromResource(sqlTestName(getClass()) + "/" + queryId + ".sql"), schemas.values(), null); + + return new PlanTemplate(RelOptUtil.toString(physicalPlan(ctx), SqlExplainLevel.ALL_ATTRIBUTES)).template; + } + + /** */ + private void updatePlan(String newPlan) { + Path targetDir = Path.of(RSRC_DIR + sqlTestName(getClass())); + + // A targetDirectory must be specified by hand when expected plans are generated. + if (targetDir == null) { + throw new RuntimeException("Please provide target directory to where save generated plans." + + " Usually plans are kept in resource folder of tests within the same module."); + } + + try { + Files.createDirectories(targetDir); + + Files.writeString(targetDir.resolve(String.format("%s.plan", queryId)), newPlan); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Execute SQL query. + * + * @param ignite Ignite. + * @param sql SQL query. + * @param params Query parameters. + */ + public static List<List<?>> sql(Ignite ignite, String sql, Object... params) { + SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(params); + + try (FieldsQueryCursor<List<?>> cur = ((IgniteEx)ignite).context().query().querySqlFields(qry, false)) { + return cur.getAll(); + } + } + + /** */ + public static class TpchUDF { Review Comment: UDF not used at all ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/tpch/TpchHelper.java: ########## @@ -148,7 +148,11 @@ public static void generateDataset(double scale, Path datasetDir) throws IOExcep * @param queryId Query identifier. */ public static String getQuery(int queryId) { - try (InputStream inputStream = TpchHelper.class.getResourceAsStream(String.format("q%d.sql", queryId))) { + String path = queryId == 15 Review Comment: Why do we need it? Query 15 is almost the same in both folders, except view is replaced to CTE (I think it's because Ignite 3 doesn't support views). I think it's more correct to leave query with view, since it's closer to original query. Having two queries looks weird. ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanTemplate.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Contains logic to process plans templates. + * Supported templates: + * <ul> + * <li>{@code ", id = 123} replaced with the {@code ", id = {id}}</li> + * <li>{@code ", hash=123} replaced with the {@code ", hash={hash}}</li> + * <li>{@code "{INDEX_CASE:IDX1,IDX2}} expands to the plans where {INDEX_CASE....} replaced with each of the index from list.</li> + * <li>{@code "{ONEOF}} start and finish with the {@code {ONEOF}} tag. Cases separated with the line "=====". + * Creates as many plans as there are cases. + * </li> + * </ul> + */ +public class PlanTemplate { + /** */ + private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+"); + + /** */ + private static final Pattern HASH_PATTERN = Pattern.compile(", hash=-?\\d+]"); Review Comment: Maybe it's better to beautify `AffinityIdentity.toString()` (add annotation `@GridToStringExclude` to `hash` field)? ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanTemplate.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Contains logic to process plans templates. + * Supported templates: + * <ul> + * <li>{@code ", id = 123} replaced with the {@code ", id = {id}}</li> + * <li>{@code ", hash=123} replaced with the {@code ", hash={hash}}</li> + * <li>{@code "{INDEX_CASE:IDX1,IDX2}} expands to the plans where {INDEX_CASE....} replaced with each of the index from list.</li> + * <li>{@code "{ONEOF}} start and finish with the {@code {ONEOF}} tag. Cases separated with the line "=====". + * Creates as many plans as there are cases. + * </li> + * </ul> + */ +public class PlanTemplate { + /** */ + private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+"); Review Comment: Maybe it's better to remove "id" from plan. It's not needed for user at all (only required for developer, for planner dumps). ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java: ########## @@ -0,0 +1,211 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import com.google.common.io.CharStreams; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.integration.tpch.TpchHelper; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.prepare.PlanningContext; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.RSRC_DIR; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; + + /** Run once, before all queries check. */ + @BeforePlansTest + public static void startAll(Class<?> testClass) throws Exception { + AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest(); + + mock.beforeFirstTest(); + + IgniteConfiguration cfg = mock.getConfiguration("server"); + + cfg.getSqlConfiguration() + .setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)); + + srv = (IgniteEx)IgnitionEx.start(cfg); + + srv.getOrCreateCache(new CacheConfiguration<>("mock") + .setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class) + .setSqlSchema("PUBLIC")); + + TpchHelper.createTables(srv); + +/* + TpchHelper.fillTables(srv, 0.01); Review Comment: It takes about 5 seconds to fill with 0.01 scale, but in this case plans are more predictable. Plans without data are irrelevant, I this we should fill the tables. ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanTemplate.java: ########## @@ -0,0 +1,152 @@ +/* + * 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.ignite.internal.processors.query.calcite.planner.tpc; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Contains logic to process plans templates. + * Supported templates: + * <ul> + * <li>{@code ", id = 123} replaced with the {@code ", id = {id}}</li> + * <li>{@code ", hash=123} replaced with the {@code ", hash={hash}}</li> + * <li>{@code "{INDEX_CASE:IDX1,IDX2}} expands to the plans where {INDEX_CASE....} replaced with each of the index from list.</li> + * <li>{@code "{ONEOF}} start and finish with the {@code {ONEOF}} tag. Cases separated with the line "=====". + * Creates as many plans as there are cases. + * </li> + * </ul> + */ +public class PlanTemplate { + /** */ + private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+"); + + /** */ + private static final Pattern HASH_PATTERN = Pattern.compile(", hash=-?\\d+]"); + + /** */ + public final String template; + + /** */ + public PlanTemplate(String template) { + this.template = HASH_PATTERN.matcher(ID_PATTERN.matcher(template) + .replaceAll(", id = {id}")) + .replaceAll(", hash={hash}"); + } + + /** + * @param actualPlan Plan to match. + * @return {@code True} if any expanded plan equals to the parameter. + */ + public boolean match(String actualPlan) { + return expandOneof(template).stream() + .flatMap(PlanTemplate::expandIndexCase) + .anyMatch(possiblePlan -> possiblePlan.equals(actualPlan)); + } + + /** Expands plans. Replace {INDEX_CASE} tag with the possible indexes. */ + private static Stream<String> expandIndexCase(String plan) { + List<String> res = new ArrayList<>(); + + res.add(plan); + + while (true) { + String idxCaseStart = "{INDEX_CASE:"; + + if (res.get(0).contains(idxCaseStart)) { + res = res.stream().flatMap(p -> { + int start = p.indexOf(idxCaseStart); + int end = p.indexOf('}', start); + + assert start != -1 && end != -1; + + String[] idxs = p.substring(start + idxCaseStart.length(), end).split(","); + + return Arrays.stream(idxs).map(idx -> p.substring(0, start) + idx + p.substring(end + 1)); + }).collect(Collectors.toList()); + } + else + break; + } + + return res.stream(); + } + + /** Expands plans. Replace {ONEOF} tag with the possible cases. */ + private static List<String> expandOneof(String plan) { + String oneOf = "{ONEOF}"; + + if (!plan.contains(oneOf)) + return Collections.singletonList(plan); + + List<StringBuffer> res = new ArrayList<>(); + + Scanner sc = new Scanner(plan); + + StringBuilder beforeOneof = new StringBuilder(); + + while (sc.hasNextLine()) { + String line = sc.nextLine(); + + if (line.trim().startsWith(oneOf)) + break; + + beforeOneof.append(line).append('\n'); + } + + boolean oneOfEnd = false; + + // Expanding first found oneof + while (sc.hasNextLine() && !oneOfEnd) { + StringBuilder oneofCase = new StringBuilder(); + + while (sc.hasNextLine()) { + String line = sc.nextLine(); + + oneOfEnd = line.trim().equals(oneOf); + + if (line.trim().matches("^=+$") || oneOfEnd) + break; + + oneofCase.append(line).append('\n'); + } + + res.add(new StringBuffer(beforeOneof).append(oneofCase)); + } + + if (!oneOfEnd) + throw new IllegalStateException(oneOf + " not closed"); + + while (sc.hasNextLine()) { + String line = sc.nextLine(); + + for (StringBuffer expanded : res) { Review Comment: Redundant braces -- 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]
