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 2021/10/18 20:44:15 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #7576: Refactor query rewriter to interfaces and implementations

Jackie-Jiang commented on a change in pull request #7576:
URL: https://github.com/apache/pinot/pull/7576#discussion_r731299717



##########
File path: pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/QueryRewriterFactory.java
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.sql.parsers.rewriter;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class QueryRewriterFactory {
+
+  private QueryRewriterFactory() {
+  }
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(QueryRewriterFactory.class);
+
+  static final List<String> DEFAULT_QUERY_VISITORS_CLASS_NAMES =

Review comment:
       ```suggestion
     static final List<String> DEFAULT_QUERY_REWRITER_CLASS_NAMES =
   ```

##########
File path: pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
##########
@@ -394,352 +356,11 @@ private static PinotQuery compileCalciteSqlToPinotQuery(String sql) {
   }
 
   private static void queryRewrite(PinotQuery pinotQuery) {
-    // Invoke compilation time functions
-    invokeCompileTimeFunctions(pinotQuery);
-
-    // Rewrite Selection list
-    rewriteSelections(pinotQuery.getSelectList());
-
-    // Update Predicate Comparison
-    Expression filterExpression = pinotQuery.getFilterExpression();
-    if (filterExpression != null) {
-      pinotQuery.setFilterExpression(updateComparisonPredicate(filterExpression));
+    for (QueryRewriter visitor : QUERY_VISITORS) {

Review comment:
       ```suggestion
       for (QueryRewriter queryRewriter : QUERY_REWRITERS) {
   ```

##########
File path: pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
##########
@@ -584,5 +584,7 @@ private CommonConstants() {
       public static final String LOWER_UNBOUNDED = LOWER_EXCLUSIVE + UNBOUNDED + DELIMITER;
       public static final String UPPER_UNBOUNDED = DELIMITER + UNBOUNDED + UPPER_EXCLUSIVE;
     }
+
+    public static final String QUERY_REWRITER_CLASS_NAMES = "pinot.query.rewriter.class.names";

Review comment:
       This should be different for each component. We don't share the config key for different component currently

##########
File path: pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/QueryRewriterFactory.java
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.sql.parsers.rewriter;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class QueryRewriterFactory {
+
+  private QueryRewriterFactory() {
+  }
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(QueryRewriterFactory.class);
+
+  static final List<String> DEFAULT_QUERY_VISITORS_CLASS_NAMES =
+      ImmutableList.of(CompileTimeFunctionsInvoker.class.getName(), SelectionsRewriter.class.getName(),
+          PredicateComparisonRewriter.class.getName(), OrdinalsUpdater.class.getName(),
+          NonAggregationGroupByToDistinctQueryRewriter.class.getName(), AliasApplier.class.getName());
+
+  public static void init(String queryVisitorsClassNamesStr) {

Review comment:
       Also other places in this class

##########
File path: pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
##########
@@ -86,6 +80,8 @@ private CalciteSqlParser() {
       SqlParser.configBuilder().setLex(PINOT_LEX).setConformance(SqlConformanceEnum.BABEL)
           .setParserFactory(SqlBabelParserImpl.FACTORY).build();
 
+  public static final List<QueryRewriter> QUERY_VISITORS = new ArrayList<>(QueryRewriterFactory.getQueryVisitors());

Review comment:
       ```suggestion
     public static final List<QueryRewriter> QUERY_REWRITERS = new ArrayList<>(QueryRewriterFactory.getQueryRewriters());
   ```

##########
File path: pinot-common/src/main/java/org/apache/pinot/sql/parsers/rewriter/QueryRewriterFactory.java
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.sql.parsers.rewriter;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.pinot.sql.parsers.CalciteSqlParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class QueryRewriterFactory {
+
+  private QueryRewriterFactory() {
+  }
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(QueryRewriterFactory.class);
+
+  static final List<String> DEFAULT_QUERY_VISITORS_CLASS_NAMES =
+      ImmutableList.of(CompileTimeFunctionsInvoker.class.getName(), SelectionsRewriter.class.getName(),
+          PredicateComparisonRewriter.class.getName(), OrdinalsUpdater.class.getName(),
+          NonAggregationGroupByToDistinctQueryRewriter.class.getName(), AliasApplier.class.getName());
+
+  public static void init(String queryVisitorsClassNamesStr) {

Review comment:
       ```suggestion
     public static void init(String queryRewriterClassNamesStr) {
   ```




-- 
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-unsubscribe@pinot.apache.org

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