walterddr commented on code in PR #9344:
URL: https://github.com/apache/pinot/pull/9344#discussion_r966525348


##########
pinot-query-planner/src/test/java/org/apache/pinot/query/QueryCompilationTest.java:
##########
@@ -181,24 +234,30 @@ private Object[][] provideQueriesWithException() {
 
   @DataProvider(name = "testQueryPlanDataProvider")
   private Object[][] provideQueriesWithExplainedPlan() {
-    return new Object[][] {
-        new Object[]{"EXPLAIN PLAN INCLUDING ALL ATTRIBUTES AS JSON FOR SELECT 
col1, col3 FROM a", "{\n"
-            + "  \"rels\": [\n" + "    {\n" + "      \"id\": \"0\",\n" + "     
 \"relOp\": \"LogicalTableScan\",\n"
-            + "      \"table\": [\n" + "        \"a\"\n" + "      ],\n" + "    
  \"inputs\": []\n" + "    },\n"
-            + "    {\n" + "      \"id\": \"1\",\n" + "      \"relOp\": 
\"LogicalProject\",\n" + "      \"fields\": [\n"
-            + "        \"col1\",\n" + "        \"col3\"\n" + "      ],\n" + "  
    \"exprs\": [\n" + "        {\n"
-            + "          \"input\": 2,\n" + "          \"name\": \"$2\"\n" + " 
       },\n" + "        {\n"
-            + "          \"input\": 1,\n" + "          \"name\": \"$1\"\n" + " 
       }\n" + "      ]\n" + "    }\n"
-            + "  ]\n" + "}"},
-        new Object[]{"EXPLAIN PLAN EXCLUDING ATTRIBUTES AS DOT FOR SELECT 
col1, COUNT(*) FROM a GROUP BY col1",
-            "Execution Plan\n" + "digraph {\n" + "\"LogicalExchange\\n\" -> 
\"LogicalAggregate\\n\" [label=\"0\"]\n"
-                + "\"LogicalAggregate\\n\" -> \"LogicalExchange\\n\" 
[label=\"0\"]\n"
-                + "\"LogicalTableScan\\n\" -> \"LogicalAggregate\\n\" 
[label=\"0\"]\n" + "}\n"},
-        new Object[]{"EXPLAIN PLAN FOR SELECT a.col1, b.col3 FROM a JOIN b ON 
a.col1 = b.col1", "Execution Plan\n"
-            + "LogicalProject(col1=[$0], col3=[$1])\n" + "  
LogicalJoin(condition=[=($0, $2)], joinType=[inner])\n"
+    return new Object[][]{
+        new Object[]{
+            "EXPLAIN PLAN INCLUDING ALL ATTRIBUTES AS JSON FOR SELECT col1, 
col3 FROM a",
+            "{\n" + "  \"rels\": [\n" + "    {\n" + "      \"id\": \"0\",\n"

Review Comment:
   nit: why this code restructure occurs? if so combine the `"{\n" with the 
next line. actually if you can don't do any these refactoring in a feature PR.



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/context/PlannerContext.java:
##########
@@ -19,15 +19,51 @@
 package org.apache.pinot.query.context;
 
 import java.util.Map;
+import org.apache.calcite.plan.Contexts;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.hep.HepProgram;
+import org.apache.calcite.prepare.PlannerImpl;
+import org.apache.calcite.prepare.Prepare;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.pinot.query.planner.logical.LogicalPlanner;
+import org.apache.pinot.query.validate.Validator;
 
 
 /**
  * PlannerContext is an object that holds all contextual information during 
planning phase.
  *
- * TODO: currently the planner context is not used since we don't support 
option or query rewrite. This construct is
- * here as a placeholder for the parsed out options.
+ * TODO: currently we don't support option or query rewrite.
+ * It is used to hold per query context for query planning, which cannot be 
shared across queries.
  */
-public class PlannerContext {
+public class PlannerContext implements AutoCloseable {
+  public PlannerContext(FrameworkConfig config, Prepare.CatalogReader 
catalogReader, RelDataTypeFactory typeFactory,
+      HepProgram hepProgram) {
+    _planner = new PlannerImpl(config);
+    _validator = new Validator(SqlStdOperatorTable.instance(), catalogReader, 
typeFactory);
+    _relOptPlanner = new LogicalPlanner(hepProgram, Contexts.EMPTY_CONTEXT);
+  }
+
+  public PlannerImpl getPlanner() {
+    return _planner;
+  }
+
+  public SqlValidator getValidator() {
+    return _validator;
+  }
+
+  public RelOptPlanner getRelOptPlanner() {
+    return _relOptPlanner;
+  }
+
+  private PlannerImpl _planner;
+
+  private SqlValidator _validator;
+
+  private RelOptPlanner _relOptPlanner;

Review Comment:
   nit: move these sections to the top of the class (in Pinot our class 
structure are member variables then functions)
   also make it final so that it cannot be modify outside of constructor of the 
class / compiler knows how to optimize getter methods.



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

Reply via email to