You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/09/29 00:35:37 UTC

[GitHub] [incubator-pinot] siddharthteotia commented on a change in pull request #6056: Add FilterOptimizer which supports optimizing query filter from both BrokerRequest and PinotQuery

siddharthteotia commented on a change in pull request #6056:
URL: https://github.com/apache/incubator-pinot/pull/6056#discussion_r496309019



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/query/optimizer/QueryOptimizer.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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.core.query.optimizer;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.request.BrokerRequest;
+import org.apache.pinot.common.request.Expression;
+import org.apache.pinot.common.request.FilterQuery;
+import org.apache.pinot.common.request.PinotQuery;
+import org.apache.pinot.common.utils.request.FilterQueryTree;
+import org.apache.pinot.common.utils.request.RequestUtils;
+import org.apache.pinot.core.query.optimizer.filter.FilterOptimizer;
+import org.apache.pinot.core.query.optimizer.filter.FlattenAndOrFilterOptimizer;
+import org.apache.pinot.core.query.optimizer.filter.MergeEqInFilterOptimizer;
+import org.apache.pinot.core.query.optimizer.filter.MergeRangeFilterOptimizer;
+import org.apache.pinot.spi.data.Schema;
+
+
+public class QueryOptimizer {
+  private static final List<FilterOptimizer> FILTER_OPTIMIZERS = Arrays
+      .asList(new FlattenAndOrFilterOptimizer(), new MergeEqInFilterOptimizer(), new MergeRangeFilterOptimizer());
+
+  /**
+   * Optimizes the given PQL query.
+   */
+  public void optimize(BrokerRequest brokerRequest, @Nullable Schema schema) {
+    FilterQuery filterQuery = brokerRequest.getFilterQuery();
+    if (filterQuery != null) {
+      FilterQueryTree filterQueryTree =
+          RequestUtils.buildFilterQuery(filterQuery.getId(), brokerRequest.getFilterSubQueryMap().getFilterQueryMap());
+      for (FilterOptimizer filterOptimizer : FILTER_OPTIMIZERS) {
+        filterQueryTree = filterOptimizer.optimize(filterQueryTree, schema);
+      }
+      RequestUtils.generateFilterFromTree(filterQueryTree, brokerRequest);
+    }
+  }
+
+  /**
+   * Optimizes the given SQL query.
+   */
+  public void optimize(PinotQuery pinotQuery, @Nullable Schema schema) {

Review comment:
       Why PinotQuery based signature for SQL? That is the end-state after getting rid of BrokerRequest right?
   
   But for now, the optimizer will get BrokerRequest for both PQL (through PQL compiler) and for SQL (through calcite compiler -> PinotQuery -> converter -> BrokerRequest). 




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

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



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