Skip to content

Commit

Permalink
[Feat](nereids) add max/min filter push down rewrite rule
Browse files Browse the repository at this point in the history
  • Loading branch information
feiniaofeiafei committed Aug 14, 2024
1 parent 4529603 commit b0a1a8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -6,7 +23,6 @@

import org.junit.jupiter.api.Test;


public class MaxMinFilterPushDownTest extends TestWithFeService implements MemoPatternMatchSupported {
@Override
protected void runBeforeAll() throws Exception {
Expand All @@ -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";
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"""
}

0 comments on commit b0a1a8e

Please sign in to comment.