morrySnow commented on code in PR #27078:
URL: https://github.com/apache/doris/pull/27078#discussion_r1395092487


##########
regression-test/suites/nereids_rules_p0/clause_eliminate/eliminate_group_by_constant.groovy:
##########
@@ -0,0 +1,118 @@
+// 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("eliminate_group_by_constant") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+
+    sql """DROP TABLE IF EXISTS t1;"""
+    sql """DROP TABLE IF EXISTS t2;"""
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t1(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t2(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """INSERT INTO t1 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t1 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t1 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t1 VALUES (3,3,3,3);"""
+
+    sql """INSERT INTO t2 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t2 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t2 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t2 VALUES (3,3,3,3);"""
+
+    // 1. single table + group by exist columns + different aggregate function 
+ having
+    qt_1_1 """select sum(c1) from t1 group by 1;"""
+    qt_1_2 """select count(c1) from t1 group by 1;"""
+    qt_1_3 """select avg(c1) from t1 group by 1;"""
+
+    qt_1_4 """select sum(c1) from t1 group by 1 having sum(c1) > 2;"""
+    qt_1_5 """select count(c1) from t1 group by 1 having count(c1) > 2;"""
+    qt_1_6 """select avg(c1) from t1 group by 1 having avg(c1) > 2;"""

Review Comment:
   add constant + non-constant



##########
regression-test/suites/nereids_rules_p0/clause_eliminate/eliminate_group_by_constant.groovy:
##########
@@ -0,0 +1,118 @@
+// 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("eliminate_group_by_constant") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+
+    sql """DROP TABLE IF EXISTS t1;"""
+    sql """DROP TABLE IF EXISTS t2;"""
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t1(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t2(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """INSERT INTO t1 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t1 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t1 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t1 VALUES (3,3,3,3);"""
+
+    sql """INSERT INTO t2 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t2 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t2 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t2 VALUES (3,3,3,3);"""
+
+    // 1. single table + group by exist columns + different aggregate function 
+ having
+    qt_1_1 """select sum(c1) from t1 group by 1;"""
+    qt_1_2 """select count(c1) from t1 group by 1;"""
+    qt_1_3 """select avg(c1) from t1 group by 1;"""

Review Comment:
   maybe need use ut to test



##########
regression-test/suites/nereids_rules_p0/clause_eliminate/eliminate_order_by_constant.groovy:
##########
@@ -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.
+
+suite("eliminate_order_by_constant") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+
+    sql """DROP TABLE IF EXISTS t1;"""
+    sql """DROP TABLE IF EXISTS t2;"""
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t1(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t2(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """INSERT INTO t1 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t1 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t1 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t1 VALUES (3,3,3,3);"""
+
+    sql """INSERT INTO t2 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t2 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t2 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t2 VALUES (3,3,3,3);"""
+
+    // 1. single table + order by exist columns + different columns
+    qt_1_1 """select c1 from t1 order by 1;"""
+    qt_1_2 """select c2 from t1 order by 1;"""
+    qt_1_3 """select c1, c2 from t1 order by 2;"""
+
+    // 2. multi table + union all + order by exist columns + different columns
+    qt_2_1 """select c1 from t1 order by 1 union all select c2 from t2 order 
by 1;"""

Review Comment:
   same with eliminate group by constant



##########
regression-test/suites/nereids_rules_p0/clause_eliminate/eliminate_limit.groovy:
##########
@@ -0,0 +1,153 @@
+// 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("eliminate_limit") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+
+    sql """DROP TABLE IF EXISTS t1;"""
+    sql """DROP TABLE IF EXISTS t2;"""
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t1(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t2(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """INSERT INTO t1 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t1 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t1 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t1 VALUES (3,3,3,3);"""
+
+    sql """INSERT INTO t2 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t2 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t2 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t2 VALUES (3,3,3,3);"""
+
+    // 1. single table + order by exist columns + different columns
+    qt_1_1 """select c1 from t1 order by 1 limit 0;"""

Review Comment:
   use shape to check



##########
regression-test/suites/nereids_rules_p0/clause_eliminate/eliminate_group_by_constant.groovy:
##########
@@ -0,0 +1,118 @@
+// 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("eliminate_group_by_constant") {
+    sql "SET enable_nereids_planner=true"
+    sql "SET enable_fallback_to_original_planner=false"
+
+    sql """DROP TABLE IF EXISTS t1;"""
+    sql """DROP TABLE IF EXISTS t2;"""
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t1(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """
+    CREATE TABLE IF NOT EXISTS t2(
+      `c1` int(11) NULL,
+      `c2` int(11) NULL,
+      `c3` int(11) NULL,
+      `c4` int(11) NULL
+    ) ENGINE = OLAP
+    DISTRIBUTED BY HASH(c1) BUCKETS 4
+    PROPERTIES (
+      "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+
+    sql """INSERT INTO t1 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t1 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t1 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t1 VALUES (3,3,3,3);"""
+
+    sql """INSERT INTO t2 VALUES (null,null,null,null);"""
+    sql """INSERT INTO t2 VALUES (1,1,1,1);"""
+    sql """INSERT INTO t2 VALUES (2,2,2,2);"""
+    sql """INSERT INTO t2 VALUES (3,3,3,3);"""
+
+    // 1. single table + group by exist columns + different aggregate function 
+ having
+    qt_1_1 """select sum(c1) from t1 group by 1;"""

Review Comment:
   add group by multi literal



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

Reply via email to