jcamachor commented on a change in pull request #557: HIVE-21338 Remove order 
by and limit for aggregates
URL: https://github.com/apache/hive/pull/557#discussion_r262800893
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSortLimitRemoveRule.java
 ##########
 @@ -0,0 +1,60 @@
+/*
+ * 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.hadoop.hive.ql.optimizer.calcite.rules;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptRuleOperand;
+import org.apache.hadoop.hive.ql.optimizer.calcite.HiveRelOptUtil;
+import org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit;
+
+/**
+ * Planner rule that removes
+ * a {@link 
org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit}.
+ * Note that this is different from HiveSortRemoveRule because this is not 
based on statistics
+ */
+public class HiveSortLimitRemoveRule extends RelOptRule {
+
+  //~ Constructors -----------------------------------------------------------
+
+  public HiveSortLimitRemoveRule() {
+    this(operand(HiveSortLimit.class, any()));
+  }
+
+  private HiveSortLimitRemoveRule(RelOptRuleOperand operand) {
+    super(operand);
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  @Override
+  public boolean matches(RelOptRuleCall call) {
+    final HiveSortLimit sortLimit = call.rel(0);
+
+    return HiveRelOptUtil.produceAtmostOneRow(sortLimit.getInput());
 
 Review comment:
   The rules should be portable between planners, i.e., a rule should not be 
unwrapping a HepRelVertex. If you want to remain generic, a workaround is 
matching RelNode. However, I would try to make the rule matchers as restrictive 
as possible, since the more information we expose to the planner, the smarter 
decisions it can make, e.g., avoiding unnecessary triggering of rules.
   You do not need recursion. When the rule is executed, we should not have 
multiple consecutive Project operators in the plan. If there were, we would get 
rid of them using ProjectMerge and ProjectRemove rules.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to