Skip to content

Commit

Permalink
support integral cast to date monotonic
Browse files Browse the repository at this point in the history
  • Loading branch information
feiniaofeiafei committed Dec 26, 2024
1 parent e77c4cf commit bb6fccd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.coercion.DateLikeType;
import org.apache.doris.nereids.types.coercion.IntegralType;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -138,6 +139,11 @@ public Expression withConstantArgs(Expression literal) {

@Override
public boolean isMonotonic(Literal lower, Literal upper) {
return child().getDataType() instanceof DateLikeType && targetType instanceof DateLikeType;
if (child().getDataType() instanceof DateLikeType && targetType instanceof DateLikeType) {
return true;
} else if (child().getDataType() instanceof IntegralType && targetType instanceof DateLikeType) {
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,14 @@ suite("int_as_date_partition_col") {
explain {
sql """SELECT count(*) FROM partition_int WHERE
(date_trunc(dt,'month')<'2024-8-01' and date_trunc(dt,'month')>'2024-6-01' )"""
contains("partitions=5/6 (p20240101,p20240201,p20240301,p20240401,p20240501)")
contains("partitions=1/6 (p20240101)")
}

explain {
sql """SELECT count(*) FROM partition_int WHERE date_trunc(dt,'month')<'2024-07-01' ;"""
contains("partitions=5/6 (p20240101,p20240201,p20240301,p20240401,p20240501)")
}

explain {
sql """SELECT count(*) FROM partition_int WHERE
!(date_trunc(dt,'month')<'2024-8-01' and date_trunc(dt,'month')>'2024-6-01' );"""
contains("partitions=5/6 (p20240101,p20240201,p20240301,p20240401,p20240501)")
}

explain {
sql """
SELECT count(*) FROM partition_int WHERE
Expand Down Expand Up @@ -201,4 +195,29 @@ suite("int_as_date_partition_col") {
sql "SELECT * FROM partition_int WHERE dt!='20241001'"
contains("partitions=5/6 (p20240101,p20240201,p20240301,p20240401,p20240501)")
}

explain {
sql "select * from partition_int where cast(dt as date)<'20240102'"
contains("partitions=2/6 (p20240101,p20240201)")
}
explain {
sql "select * from partition_int where cast(dt as datetime)<'20240102'"
contains("partitions=2/6 (p20240101,p20240201)")
}
explain {
sql "select * from partition_int where cast(dt as datetime)>'20240302'"
contains("partitions=3/6 (p20240101,p20240401,p20240501)")
}
explain {
sql "select * from partition_int where cast(dt as date) is null"
contains("partitions=5/6 (p20240101,p20240201,p20240301,p20240401,p20240501)")
}
explain {
sql "SELECT count(*) FROM partition_int WHERE date_trunc(dt,'month')>'2024-3-01'"
contains("partitions=3/6 (p20240101,p20240401,p20240501)")
}
explain {
sql "SELECT count(*) FROM partition_int WHERE date_trunc(dt,'month')>='2024-3-01'"
contains("partitions=4/6 (p20240101,p20240301,p20240401,p20240501)")
}
}

0 comments on commit bb6fccd

Please sign in to comment.