alex-plekhanov commented on a change in pull request #9821:
URL: https://github.com/apache/ignite/pull/9821#discussion_r806914023



##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
##########
@@ -88,8 +89,23 @@
 import org.apache.ignite.internal.processors.query.calcite.util.Service;
 import org.jetbrains.annotations.Nullable;
 
+import static org.apache.ignite.IgniteSystemProperties.getLong;
+
 /** */
 public class CalciteQueryProcessor extends GridProcessorAdapter implements 
QueryEngine {
+    /**
+     * Default planner timeout, in ms.
+     */
+    private static final long 
DFLT_IGNITE_EXPERIMENTAL_SQL_ENGINE_PLANNER_TIMEOUT = 15000;

Review comment:
       Let's use `IGNITE_CALCITE` instead of `IGNITE_EXPERIMENTAL_SQL_ENGINE`

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
##########
@@ -1299,4 +1308,110 @@ public void testNotStandardFunctions() throws Exception 
{
             checkSplitAndSerialization(phys, publicSchema);
         }
     }
+
+    /** */
+    @Test
+    public void testLongPlanningTimeout() throws Exception {

Review comment:
       `PlannerTest` already has a lot of unsorted tests, let's move this test 
to another class.

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
##########
@@ -1299,4 +1308,110 @@ public void testNotStandardFunctions() throws Exception 
{
             checkSplitAndSerialization(phys, publicSchema);
         }
     }
+
+    /** */
+    @Test
+    public void testLongPlanningTimeout() throws Exception {
+        IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
+
+        TestTable t1 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("B", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t2 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t3 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("B", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t4 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
+
+        publicSchema.addTable("T1", t1);
+        publicSchema.addTable("T2", t2);
+        publicSchema.addTable("T3", t3);
+        publicSchema.addTable("T4", t4);

Review comment:
       Let's use static methods to simplify this:
   ```
   createSchema(createTable("T1", IgniteDistributions.single(), "A", 
Integer.class, ...), ...);
   ```

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
##########
@@ -1299,4 +1308,110 @@ public void testNotStandardFunctions() throws Exception 
{
             checkSplitAndSerialization(phys, publicSchema);
         }
     }
+
+    /** */
+    @Test
+    public void testLongPlanningTimeout() throws Exception {
+        IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
+
+        TestTable t1 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("B", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t2 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t3 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("B", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t4 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
+
+        publicSchema.addTable("T1", t1);
+        publicSchema.addTable("T2", t2);
+        publicSchema.addTable("T3", t3);
+        publicSchema.addTable("T4", t4);
+
+        SchemaPlus schema = createRootSchema(false)
+            .add("PUBLIC", publicSchema);
+
+        String sql = "SELECT * FROM T1 JOIN T2 ON T1.A = T2.A JOIN T3 ON T3.B 
= T1.B AND T3.C = T2.C JOIN T4" +

Review comment:
       As for me, relaying on long JOINs planning - it's not a good idea (I 
hope we will optimise planning of such queries in the future). Perhaps it's 
better to override and slow down some method in TestTable/Index/Statistics

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/BaseQueryContext.java
##########
@@ -154,13 +154,17 @@
     /** */
     private final GridQueryCancel qryCancel;
 
+    /** */
+    private final long plannerTimeout;

Review comment:
       Why do we need it in BaseQueryContext? Looks like store this field in 
PlanningContext is enough.

##########
File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
##########
@@ -88,8 +89,23 @@
 import org.apache.ignite.internal.processors.query.calcite.util.Service;
 import org.jetbrains.annotations.Nullable;
 
+import static org.apache.ignite.IgniteSystemProperties.getLong;
+
 /** */
 public class CalciteQueryProcessor extends GridProcessorAdapter implements 
QueryEngine {
+    /**
+     * Default planner timeout, in ms.
+     */
+    private static final long 
DFLT_IGNITE_EXPERIMENTAL_SQL_ENGINE_PLANNER_TIMEOUT = 15000;
+
+    /**
+     * Determines whether to use the experimental sql, calcite based, engine.
+     */
+    @SystemProperty(value = "Timeout of experimental sql engine planner 
timeout, in ms", type = Long.class,

Review comment:
       The class that uses this annotation should be in 
`CommandLineStartup#PROPS_CLS` (perhaps it's better to move property to 
`IgniteSystemProperties`)

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
##########
@@ -1299,4 +1308,110 @@ public void testNotStandardFunctions() throws Exception 
{
             checkSplitAndSerialization(phys, publicSchema);
         }
     }
+
+    /** */
+    @Test
+    public void testLongPlanningTimeout() throws Exception {
+        IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
+
+        TestTable t1 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("B", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t2 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t3 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("B", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        TestTable t4 = new TestTable(
+            new RelDataTypeFactory.Builder(f)
+                .add("A", f.createJavaType(Integer.class))
+                .add("C", f.createJavaType(Integer.class))
+                .build()) {
+
+            @Override public IgniteDistribution distribution() {
+                return IgniteDistributions.broadcast();
+            }
+        };
+
+        IgniteSchema publicSchema = new IgniteSchema("PUBLIC");
+
+        publicSchema.addTable("T1", t1);
+        publicSchema.addTable("T2", t2);
+        publicSchema.addTable("T3", t3);
+        publicSchema.addTable("T4", t4);
+
+        SchemaPlus schema = createRootSchema(false)
+            .add("PUBLIC", publicSchema);
+
+        String sql = "SELECT * FROM T1 JOIN T2 ON T1.A = T2.A JOIN T3 ON T3.B 
= T1.B AND T3.C = T2.C JOIN T4" +
+            " ON T4.C = T3.C AND T4.A = T1.A";
+
+        PlanningContext ctx = PlanningContext.builder()
+            .parentContext(BaseQueryContext.builder()
+                .frameworkConfig(newConfigBuilder(FRAMEWORK_CONFIG)
+                    .defaultSchema(schema)
+                    .costFactory(new IgniteCostFactory(1, 100, 1, 1))
+                    .build())
+                .logger(log)
+                .plannerTimeout(PLANNER_TIMEOUT)
+                .build()
+            )
+            .query(sql)
+            .build();
+
+        try (IgnitePlanner planner = ctx.planner()) {
+            assertNotNull(planner);
+
+            String qry = ctx.query();
+
+            assertNotNull(qry);
+
+            SqlNode sqlNode = planner.parse(qry);
+
+            ValidationResult validated = 
planner.validateAndGetTypeMetadata(sqlNode);
+
+            AtomicReference<IgniteRel> plan = new AtomicReference<>();
+
+            GridTestUtils.assertTimeout(2 * PLANNER_TIMEOUT, 
TimeUnit.MILLISECONDS, () -> {
+                plan.set(PlannerHelper.optimize(validated.sqlNode(), planner, 
log));
+            });
+
+            assertNotNull(plan.get());

Review comment:
       Why not use `physicalPlan()`?

##########
File path: 
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
##########
@@ -87,6 +93,9 @@
 //@WithSystemProperty(key = "calcite.debug", value = "true")
 @SuppressWarnings({"TooBroadScope", "FieldCanBeLocal", "TypeMayBeWeakened"})
 public class PlannerTest extends AbstractPlannerTest {
+    /** */
+    private static final long PLANNER_TIMEOUT = 5_000;

Review comment:
       Let's use smaller timeout (1 sec for example) to make tests pass faster.




-- 
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]


Reply via email to