From b0a1a8ef9ada2f9ab07a8c4510cf653b37977ca3 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Wed, 14 Aug 2024 10:48:09 +0800 Subject: [PATCH] [Feat](nereids) add max/min filter push down rewrite rule --- .../rewrite/MaxMinFilterPushDownTest.java | 23 ++++++++++++++++++- .../max_min_filter_push_down.groovy | 6 ++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/MaxMinFilterPushDownTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/MaxMinFilterPushDownTest.java index d4461162424926c..0c8cced405d317a 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/MaxMinFilterPushDownTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/MaxMinFilterPushDownTest.java @@ -1,3 +1,20 @@ +// 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; import org.apache.doris.nereids.util.MemoPatternMatchSupported; @@ -6,7 +23,6 @@ import org.junit.jupiter.api.Test; - public class MaxMinFilterPushDownTest extends TestWithFeService implements MemoPatternMatchSupported { @Override protected void runBeforeAll() throws Exception { @@ -26,6 +42,7 @@ public void testMaxRewrite() { PlanChecker.from(connectContext).analyze(sql).rewrite() .matches(logicalFilter(logicalOlapScan()).when(filter -> filter.getConjuncts().size() == 1)); } + @Test public void testMinRewrite() { String sql = "select id, min(score) from max_t group by id having min(score)<10"; @@ -39,24 +56,28 @@ public void testMaxNotRewrite0() { PlanChecker.from(connectContext).analyze(sql).rewrite() .nonMatch(logicalFilter(logicalOlapScan())); } + @Test public void testMinNotRewrite1() { String sql = "select id, min(score) from max_t group by id having min(score)>10"; PlanChecker.from(connectContext).analyze(sql).rewrite() .nonMatch(logicalFilter(logicalOlapScan())); } + @Test public void testMinNotRewrite2() { String sql = "select id, min(score), max(score) from max_t group by id having min(score)>10"; PlanChecker.from(connectContext).analyze(sql).rewrite() .nonMatch(logicalFilter(logicalOlapScan())); } + @Test public void testMinNotRewrite3() { String sql = "select id, min(score), count(score) from max_t group by id having min(score)>10"; PlanChecker.from(connectContext).analyze(sql).rewrite() .nonMatch(logicalFilter(logicalOlapScan())); } + @Test public void testMinNotRewrite4() { String sql = "select id, max(score) from max_t group by id having abs(max(score))>10"; diff --git a/regression-test/suites/nereids_rules_p0/max_min_filter_push_down/max_min_filter_push_down.groovy b/regression-test/suites/nereids_rules_p0/max_min_filter_push_down/max_min_filter_push_down.groovy index 9beb80b414b013f..98c48570dfdb55e 100644 --- a/regression-test/suites/nereids_rules_p0/max_min_filter_push_down/max_min_filter_push_down.groovy +++ b/regression-test/suites/nereids_rules_p0/max_min_filter_push_down/max_min_filter_push_down.groovy @@ -179,7 +179,7 @@ suite("max_min_filter_push_down") { qt_char100_cmp_num_cannot_rewrite_res """select d_int,min(d_char100) from max_min_filter_push_down2 group by d_int having min(d_char100)<10 order by 1,2;""" qt_datetimev2_res """select d_int,min(d_datetimev2) from max_min_filter_push_down2 group by d_int having min(d_datetimev2)<'2020-01-09' order by 1,2;""" qt_datev2_res """select d_int,max(d_datev2) from max_min_filter_push_down2 group by d_int having max(d_datev2)>'2020-01-09 10:00:00' order by 1,2;""" - qt_smallint_group_by_key_res """select max(d_smallint) from max_min_filter_push_down2 group by d_smallint having max(d_smallint)>10 order by 1,2;""" - qt_tinyint_group_by_key_res """select min(d_tinyint) from max_min_filter_push_down2 group by d_tinyint having min(d_tinyint)<10 order by 1,2;""" - qt_char100_group_by_key_res """select max(d_char100) from max_min_filter_push_down2 group by d_char100 having max(d_char100)>'ab' order by 1,2;""" + qt_smallint_group_by_key_res """select max(d_smallint) from max_min_filter_push_down2 group by d_smallint having max(d_smallint)>10 order by 1;""" + qt_tinyint_group_by_key_res """select min(d_tinyint) from max_min_filter_push_down2 group by d_tinyint having min(d_tinyint)<10 order by 1;""" + qt_char100_group_by_key_res """select max(d_char100) from max_min_filter_push_down2 group by d_char100 having max(d_char100)>'ab' order by 1;""" } \ No newline at end of file