yashmayya commented on code in PR #17328:
URL: https://github.com/apache/pinot/pull/17328#discussion_r2621066365
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotQueryRuleSets.java:
##########
@@ -252,4 +254,33 @@ private PinotQueryRuleSets() {
CoreRules.FILTER_REDUCE_EXPRESSIONS
);
//@formatter:on
+
+ public static List<RelOptRule> getPinotPostRules(QueryEnvironment.Config
envConfig) {
+ int sortExchangeCopyLimit = envConfig.getSortExchangeCopyLimit();
+ if (sortExchangeCopyLimit == -1) {
+ return PINOT_POST_RULES;
+ } else {
+ return replaceAll(
+ PINOT_POST_RULES,
+ PinotSortExchangeCopyRule.class,
+ ImmutablePinotSortExchangeCopyRule.Config.builder()
+ .from(PinotSortExchangeCopyRule.Config.DEFAULT)
+ .fetchLimitThreshold(sortExchangeCopyLimit)
+ .build()
+ .toRule()
+ );
+ }
+ }
+
+ private static <C extends RelOptRule> List<RelOptRule> replaceAll(List<?
extends RelOptRule> rules,
+ Class<? extends C> clazz, C newRule) {
+ List<RelOptRule> updatedRules = new ArrayList<>(rules);
+ for (int i = 0; i < updatedRules.size(); i++) {
+ RelOptRule rule = updatedRules.get(i);
+ if (clazz.isInstance(rule)) {
+ updatedRules.set(i, newRule);
+ }
+ }
+ return updatedRules;
+ }
Review Comment:
This seems like a pretty clunky way of configuring rules IMO, especially
once we have multiple such scenarios. I'm wondering if there's no simpler way
to do this?
##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironmentConfigFactory.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.config.provider.TableCache;
+import org.apache.pinot.common.utils.config.QueryOptionsUtils;
+import org.apache.pinot.query.routing.WorkerManager;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+/// A factory class to create QueryEnvironment.Config instances.
+///
+/// This includes the ability to cus
+public class QueryEnvironmentConfigFactory {
+ private QueryEnvironmentConfigFactory() {
+ }
+
+ public static ImmutableQueryEnvironment.Config create(
+ String database, Map<String, String> queryOptions,
+ long requestId, PinotConfiguration config, TableCache tableCache,
WorkerManager workerManager,
+ @Nullable Set<String> defaultDisabledPlannerRules) {
Review Comment:
Should this be nullable?
##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironmentConfigFactory.java:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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.Map;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.pinot.common.config.provider.TableCache;
+import org.apache.pinot.common.utils.config.QueryOptionsUtils;
+import org.apache.pinot.query.routing.WorkerManager;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants;
+
+/// A factory class to create QueryEnvironment.Config instances.
+///
+/// This includes the ability to cus
Review Comment:
nit: incomplete
##########
pinot-query-planner/src/test/resources/queries/OrderByPlans.json:
##########
@@ -61,6 +61,29 @@
"\n"
]
},
+ {
+ "description": "Select * with order by and super large limit but query
option",
+ "sql": "SET sortExchangeCopyThreshold=20000000; EXPLAIN PLAN FOR
SELECT * FROM b order by col1 LIMIT 10000000",
+ "output": [
+ "Execution Plan",
+ "\nLogicalSort(sort0=[$0], dir0=[ASC], offset=[0],
fetch=[10000000])",
+ "\n PinotLogicalSortExchange(distribution=[hash], collation=[[0]],
isSortOnSender=[false], isSortOnReceiver=[true])",
+ "\n LogicalSort(sort0=[$0], dir0=[ASC], fetch=[10000000])",
+ "\n PinotLogicalTableScan(table=[[default, b]])",
+ "\n"
+ ]
+ },
+ {
+ "description": "Select * with order by and small large limit but query
option",
Review Comment:
> small large
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotSortExchangeCopyRule.java:
##########
@@ -100,23 +104,22 @@ public void onMatch(RelOptRuleCall call) {
call.transformTo(sortCopy);
}
+ @Value.Immutable
public interface Config extends RelRule.Config {
- Config DEFAULT = ImmutableSortExchangeCopyRule.Config.of()
- .withOperandFor(LogicalSort.class, PinotLogicalSortExchange.class);
+ Config DEFAULT = ImmutablePinotSortExchangeCopyRule.Config.builder()
+ .operandSupplier(b0 ->
+ b0.operand(LogicalSort.class)
+ .oneInput(b1 ->
b1.operand(PinotLogicalSortExchange.class).anyInputs()))
+ .build();
Review Comment:
Not related to this PR, but I don't understand what this config builder is
actually trying to do?
--
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]