morrySnow commented on code in PR #14862:
URL: https://github.com/apache/doris/pull/14862#discussion_r1042164044
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java:
##########
@@ -70,6 +70,9 @@ public enum RuleType {
CHECK_ROW_POLICY(RuleTypeClass.REWRITE),
+ ResolveOrdinalInOrderBy(RuleTypeClass.REWRITE),
+ ResolveOrdinalInGroupBy(RuleTypeClass.REWRITE),
Review Comment:
name format~
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
+ List<Slot> childOutput =
sortNode.child().getOutput();
+ List<OrderKey> orderKeys = sortNode.getOrderKeys();
+ List<OrderKey> orderKeysWithoutConst = new
ArrayList<>();
+ for (OrderKey k : orderKeys) {
+ Expression expression = k.getExpr();
+ expression =
FoldConstantRule.INSTANCE.rewrite(expression);
+ if (expression instanceof IntegerLikeLiteral) {
+ IntegerLikeLiteral i =
(IntegerLikeLiteral) expression;
+ int ord = i.getIntValue();
+ checkOrd(ord, childOutput.size());
+ orderKeysWithoutConst
+ .add(new
OrderKey(childOutput.get(ord - 1), k.isAsc(), k.isNullFirst()));
+ } else {
+ orderKeysWithoutConst.add(k);
+ }
+ }
+ return
sortNode.withOrderByKey(orderKeysWithoutConst);
+ })
+ ))
+ .add(RuleType.ResolveOrdinalInGroupBy.build(
+ logicalAggregate().then(agg -> {
+ List<NamedExpression> aggOutput =
agg.getOutputExpressions();
+ List<Expression> groupByWithoutConst = new
ArrayList<>();
+ for (Expression groupByExpr :
agg.getGroupByExpressions()) {
+ groupByExpr =
FoldConstantRule.INSTANCE.rewrite(groupByExpr);
+ if (groupByExpr instanceof IntegerLikeLiteral)
{
+ IntegerLikeLiteral i =
(IntegerLikeLiteral) groupByExpr;
+ int ord = i.getIntValue();
+ Expression aggExpr = aggOutput.get(ord -
1);
+ if
(!CollectionUtils.isEmpty(aggExpr.children())
+ && aggExpr.child(0) instanceof
Literal) {
+ continue;
+ }
+ checkOrd(ord, aggOutput.size());
+ groupByWithoutConst.add(aggExpr);
+ } else {
+ groupByWithoutConst.add(groupByExpr);
+ }
+ }
+ return new LogicalAggregate(groupByWithoutConst,
agg.getOutputExpressions(), agg.child());
+ }))).build();
+ }
+
+ private void checkOrd(int ord, int childOutputSize) {
+ if (ord < 1 || ord > childOutputSize) {
+ throw new IllegalStateException(String.format("INVALID ORD: %s",
ord));
Review Comment:
not use all uppercase in error msg, and not use abbreviation, leave a msg
with more ditail for easy understand.
the legacy planner's error msg is "ordinal exceeds number of items in select
list: 3"
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
Review Comment:
in nereids, not use xxxNode as a plan var name. just use sort or logicalSort
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
+ List<Slot> childOutput =
sortNode.child().getOutput();
+ List<OrderKey> orderKeys = sortNode.getOrderKeys();
+ List<OrderKey> orderKeysWithoutConst = new
ArrayList<>();
+ for (OrderKey k : orderKeys) {
+ Expression expression = k.getExpr();
+ expression =
FoldConstantRule.INSTANCE.rewrite(expression);
+ if (expression instanceof IntegerLikeLiteral) {
+ IntegerLikeLiteral i =
(IntegerLikeLiteral) expression;
+ int ord = i.getIntValue();
+ checkOrd(ord, childOutput.size());
+ orderKeysWithoutConst
+ .add(new
OrderKey(childOutput.get(ord - 1), k.isAsc(), k.isNullFirst()));
+ } else {
+ orderKeysWithoutConst.add(k);
+ }
+ }
+ return
sortNode.withOrderByKey(orderKeysWithoutConst);
+ })
+ ))
+ .add(RuleType.ResolveOrdinalInGroupBy.build(
+ logicalAggregate().then(agg -> {
+ List<NamedExpression> aggOutput =
agg.getOutputExpressions();
+ List<Expression> groupByWithoutConst = new
ArrayList<>();
+ for (Expression groupByExpr :
agg.getGroupByExpressions()) {
+ groupByExpr =
FoldConstantRule.INSTANCE.rewrite(groupByExpr);
+ if (groupByExpr instanceof IntegerLikeLiteral)
{
+ IntegerLikeLiteral i =
(IntegerLikeLiteral) groupByExpr;
+ int ord = i.getIntValue();
+ Expression aggExpr = aggOutput.get(ord -
1);
+ if
(!CollectionUtils.isEmpty(aggExpr.children())
+ && aggExpr.child(0) instanceof
Literal) {
+ continue;
+ }
+ checkOrd(ord, aggOutput.size());
+ groupByWithoutConst.add(aggExpr);
Review Comment:
ditto
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
+ List<Slot> childOutput =
sortNode.child().getOutput();
+ List<OrderKey> orderKeys = sortNode.getOrderKeys();
+ List<OrderKey> orderKeysWithoutConst = new
ArrayList<>();
+ for (OrderKey k : orderKeys) {
+ Expression expression = k.getExpr();
+ expression =
FoldConstantRule.INSTANCE.rewrite(expression);
Review Comment:
u could get connectcontext in ctx, when u use `thenapply` instead of `then`
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
+ List<Slot> childOutput =
sortNode.child().getOutput();
+ List<OrderKey> orderKeys = sortNode.getOrderKeys();
+ List<OrderKey> orderKeysWithoutConst = new
ArrayList<>();
+ for (OrderKey k : orderKeys) {
+ Expression expression = k.getExpr();
+ expression =
FoldConstantRule.INSTANCE.rewrite(expression);
+ if (expression instanceof IntegerLikeLiteral) {
+ IntegerLikeLiteral i =
(IntegerLikeLiteral) expression;
+ int ord = i.getIntValue();
+ checkOrd(ord, childOutput.size());
+ orderKeysWithoutConst
+ .add(new
OrderKey(childOutput.get(ord - 1), k.isAsc(), k.isNullFirst()));
+ } else {
+ orderKeysWithoutConst.add(k);
+ }
+ }
+ return
sortNode.withOrderByKey(orderKeysWithoutConst);
Review Comment:
if no ordinal in orderkeys, we should return original object for fast equals
to reduce plan time
##########
regression-test/suites/nereids_syntax_p0/group_by_constant.groovy:
##########
@@ -29,4 +29,11 @@ suite("group_by_constant") {
qt_select_1 """
select 'str', sum(lo_tax), lo_orderkey, max(lo_discount), 1 from
lineorder, customer group by 3, 5, 'str', 1, lo_orderkey order by lo_orderkey;
"""
+
+ qt_sql """SELECT lo_custkey, lo_partkey, SUM(lo_tax) FROM lineorder GROUP
BY 1, 2"""
+
+ qt_sql """SELECT lo_partkey, lo_custkey, SUM(lo_tax) FROM lineorder GROUP
BY 1, 2"""
+
+ qt_sql """SELECT lo_partkey, 1, SUM(lo_tax) FROM lineorder GROUP BY 1, 1
+ 1"""
Review Comment:
add some other type constant cases
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/EliminateOrderByConstant.java:
##########
@@ -0,0 +1,49 @@
+// 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.doris.nereids.rules.rewrite.logical;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * SELECT * FROM lineorder ORDER BY 'f' -> SELECT * FROM lineorder
+ */
+public class EliminateOrderByConstant extends OneRewriteRuleFactory {
+
+ @Override
+ public Rule build() {
+ return logicalSort().then(sort -> {
+ List<OrderKey> orderKeysWithoutConst = sort
+ .getOrderKeys()
+ .stream()
+ .filter(k -> !(k.getExpr() instanceof Literal))
Review Comment:
use Expression#isConstant
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
+ List<Slot> childOutput =
sortNode.child().getOutput();
+ List<OrderKey> orderKeys = sortNode.getOrderKeys();
+ List<OrderKey> orderKeysWithoutConst = new
ArrayList<>();
+ for (OrderKey k : orderKeys) {
+ Expression expression = k.getExpr();
+ expression =
FoldConstantRule.INSTANCE.rewrite(expression);
Review Comment:
remove constant is in another rule
##########
regression-test/suites/nereids_syntax_p0/order_by_const.groovy:
##########
@@ -0,0 +1,25 @@
+// 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.
+
+suite("order_by_const") {
+ sql "SET enable_nereids_planner=true"
+ sql "SET enable_fallback_to_original_planner=false"
Review Comment:
enable vectorized engine explicitly
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ResolveOrdinalInOrderByAndGroupBy.java:
##########
@@ -0,0 +1,96 @@
+// 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.doris.nereids.rules.analysis;
+
+import org.apache.doris.nereids.properties.OrderKey;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import
org.apache.doris.nereids.rules.expression.rewrite.rules.FoldConstantRule;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.collections.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SELECT col1, col2 FROM t1 ORDER BY 1 -> SELECT col1, col2 FROM t1 ORDER BY
col1
+ * SELECT col1, SUM(col2) FROM t1 GROUP BY 1 -> SELECT col1, SUM(col2) FROM t1
GROUP BY col1
+ */
+public class ResolveOrdinalInOrderByAndGroupBy implements AnalysisRuleFactory {
+
+ @Override
+ public List<Rule> buildRules() {
+ return ImmutableList.<Rule>builder()
+ .add(RuleType.ResolveOrdinalInOrderBy.build(
+ logicalSort().then(sortNode -> {
+ List<Slot> childOutput =
sortNode.child().getOutput();
+ List<OrderKey> orderKeys = sortNode.getOrderKeys();
+ List<OrderKey> orderKeysWithoutConst = new
ArrayList<>();
Review Comment:
if only process ordinal, the var's name should be
`orderkeysAfterReplaceOrdinal`
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/EliminateGroupByConstant.java:
##########
@@ -50,6 +51,7 @@ public Rule build() {
List<NamedExpression> outputExprs =
aggregate.getOutputExpressions();
Set<Expression> slotGroupByExprs = Sets.newLinkedHashSet();
for (Expression expression : groupByExprs) {
+ expression = FoldConstantRule.INSTANCE.rewrite(expression);
Review Comment:
remove constant do not need to do FoldConstantRule, just use
Expression#isConstant
--
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]