diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateFormat.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateFormat.java index 2f5177d23f826b7..1ae130d876d965b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateFormat.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/DateFormat.java @@ -53,6 +53,10 @@ public class DateFormat extends ScalarFunction FunctionSignature.ret(VarcharType.SYSTEM_DEFAULT).args(DateType.INSTANCE, VarcharType.SYSTEM_DEFAULT) ); + private static final Set monoFormat = ImmutableSet.of("yyyyMMdd", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", + "%Y", "%Y-%m", "%Y-%m-%d", "%Y-%m-%d%H", "%Y-%m-%d%H:%i", "%Y-%m-%d%H:%i:%s", "%Y-%m-%d%H:%i:%S", + "%Y-%m-%d%T", "%Y%m%d", "%Y%m"); + /** * constructor with 2 arguments. */ @@ -86,10 +90,7 @@ public boolean isMonotonic() { return false; } VarcharLiteral varcharLiteral = (VarcharLiteral) format; - String str = varcharLiteral.getValue(); - Set monoFormat = ImmutableSet.of("yyyyMMdd", "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "%Y", "%Y-%m", - "%Y-%m-%d", "%Y-%m-%d %H", "%Y-%m-%d %H:%i", "%Y-%m-%d %H:%i:%s", "%Y-%m-%d %H:%i:%S", "%Y-%m-%d %T", - "%Y%m%d", "%Y%m"); + String str = varcharLiteral.getValue().replace(" ", ""); return monoFormat.contains(str); } diff --git a/regression-test/suites/nereids_rules_p0/partition_prune/always_mono_func.groovy b/regression-test/suites/nereids_rules_p0/partition_prune/always_mono_func.groovy index 722acda8abc1c7e..7fc74d7eb2ac6c1 100644 --- a/regression-test/suites/nereids_rules_p0/partition_prune/always_mono_func.groovy +++ b/regression-test/suites/nereids_rules_p0/partition_prune/always_mono_func.groovy @@ -106,7 +106,10 @@ suite("always_mono_func") { sql """select * from always_mono_func where date_format(dt, "%Y%m") > "20190101" """ contains("partitions=2/5 (p4,p5)") } - + explain { + sql """select * from always_mono_func where date_format(dt, "%Y %m") > "2019 01" """ + contains("partitions=2/5 (p4,p5)") + } explain { sql """ select * from always_mono_func where last_day(dt) > "2019-01-01" """