siddharthteotia commented on a change in pull request #8340:
URL: https://github.com/apache/pinot/pull/8340#discussion_r828821713



##########
File path: 
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java
##########
@@ -0,0 +1,156 @@
+/**
+ * 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.pinot.query;
+
+import java.util.Collection;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.plan.Contexts;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.hep.HepProgramBuilder;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.prepare.PlannerImpl;
+import org.apache.calcite.prepare.Prepare;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
+import org.apache.calcite.sql2rel.StandardConvertletTable;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.pinot.query.context.PlannerContext;
+import org.apache.pinot.query.parser.CalciteSqlParser;
+import org.apache.pinot.query.planner.LogicalPlanner;
+import org.apache.pinot.query.planner.QueryPlan;
+import org.apache.pinot.query.planner.StagePlanner;
+import org.apache.pinot.query.routing.WorkerManager;
+import org.apache.pinot.query.rules.PinotQueryRuleSets;
+import org.apache.pinot.query.type.TypeFactory;
+import org.apache.pinot.query.validate.Validator;
+
+
+/**
+ * The {@code QueryEnvironment} contains the main entrypoint for query 
planning.
+ *
+ * <p>It provide the higher level entry interface to convert a SQL string into 
a {@link QueryPlan}.
+ */
+public class QueryEnvironment {
+  private final RelDataTypeFactory _typeFactory;
+  private final CalciteSchema _rootSchema;
+  private final WorkerManager _workerManager;
+  private final FrameworkConfig _config;
+
+  private final PlannerImpl _planner;
+  private final SqlValidator _validator;
+  private final Prepare.CatalogReader _catalogReader;
+  private final Collection<RelOptRule> _logicalRuleSet;
+  private final RelOptPlanner _relOptPlanner;
+
+  public QueryEnvironment(TypeFactory typeFactory, CalciteSchema rootSchema, 
WorkerManager workerManager) {
+    _typeFactory = typeFactory;
+    _rootSchema = rootSchema;
+    _workerManager = workerManager;
+    _config = Frameworks.newConfigBuilder().traitDefs().build();
+
+    // this is only here as a placeholder for SqlToRelConverter expandView 
implementation.
+    _planner = new PlannerImpl(_config);
+
+    // catalog
+    _catalogReader = new CalciteCatalogReader(_rootSchema, 
_rootSchema.path(null), _typeFactory, null);

Review comment:
       IIUC, `QueryEnvironment` instance is created per compiled query ? If so, 
instantiating the entire catalog (requiring calls to TableCache) per query can 
be expensive ? 
   
   On the other hand, if this is created once as a global environment holder / 
entry point for compiling every query, then how do we ensure thread safety ?




-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to