yujun777 commented on code in PR #62548: URL: https://github.com/apache/doris/pull/62548#discussion_r3092269206
########## regression-test/suites/nereids_rules_p0/count_null_not_count_star/count_null_not_count_star.groovy: ########## @@ -0,0 +1,80 @@ +// 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("count_null_not_count_star") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql "DROP TABLE IF EXISTS count_null_test" + + sql """ + create table count_null_test(pk int, a int, b int) distributed by hash(pk) buckets 10 + properties('replication_num' = '1'); + """ + + sql """ + insert into count_null_test values(1, 1, 1), (2, null, 2), (3, 3, null), (4, null, null); + """ + sql "sync" + + // count(null) should always return 0 regardless of row count + order_qt_count_null """select count(null) from count_null_test""" + + // count(*) should return total number of rows + order_qt_count_star """select count(*) from count_null_test""" + + // count(1) should be equivalent to count(*) + order_qt_count_literal """select count(1) from count_null_test""" + + // count(null) with group by should return 0 for each group + order_qt_count_null_group_by """select pk, count(null) from count_null_test group by pk order by pk""" + + // mixed: count(null) vs count(*) vs count(column) + order_qt_count_mixed """select count(null), count(*), count(a), count(b) from count_null_test""" + + // count(null) in subquery with union all + order_qt_count_null_union """ + select count(null) from ( + select a from count_null_test + union all + select a from count_null_test + ) t + """ + + // count(null) as window function Review Comment: Fixed. Window test kept as a correctness check (count(null)=0 in window context). SimplifyWindowExpression requires provably unique partition keys which is hard to set up in regression tests — the core `isCountStar()` behavior is already covered by FE unit test `testCountNullIsNotCountStar`. ########## regression-test/suites/nereids_rules_p0/count_null_not_count_star/count_null_not_count_star.groovy: ########## @@ -0,0 +1,80 @@ +// 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("count_null_not_count_star") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql "DROP TABLE IF EXISTS count_null_test" + + sql """ + create table count_null_test(pk int, a int, b int) distributed by hash(pk) buckets 10 + properties('replication_num' = '1'); + """ + + sql """ + insert into count_null_test values(1, 1, 1), (2, null, 2), (3, 3, null), (4, null, null); + """ + sql "sync" + + // count(null) should always return 0 regardless of row count + order_qt_count_null """select count(null) from count_null_test""" + + // count(*) should return total number of rows + order_qt_count_star """select count(*) from count_null_test""" + + // count(1) should be equivalent to count(*) + order_qt_count_literal """select count(1) from count_null_test""" + + // count(null) with group by should return 0 for each group + order_qt_count_null_group_by """select pk, count(null) from count_null_test group by pk order by pk""" + + // mixed: count(null) vs count(*) vs count(column) + order_qt_count_mixed """select count(null), count(*), count(a), count(b) from count_null_test""" + + // count(null) in subquery with union all + order_qt_count_null_union """ + select count(null) from ( + select a from count_null_test + union all + select a from count_null_test + ) t + """ + + // count(null) as window function + order_qt_count_null_window """ + select pk, count(null) over (order by pk) from count_null_test order by pk + """ + + // count(null) through join must still return 0, not get rewritten by PushDownAggThroughJoin Review Comment: Fixed. Replaced with a grouped join: `select t1.pk, count(null), count(*) from ... group by t1.pk`. Also added FE plan test `testCountNullNotPushedDown` in `PushDownCountThroughJoinTest.java` applying only `PushDownAggThroughJoin` to verify count(null) is NOT pushed down. -- 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]
