From 32648e5dde10feeed3c3e6b1ba8d6dacdbc5750a Mon Sep 17 00:00:00 2001 From: LiBinfeng Date: Thu, 26 Dec 2024 15:40:47 +0800 Subject: [PATCH] fix p0 and feut --- .../rules/SimplifyComparisonPredicate.java | 3 ++ .../expressions/literal/DateLiteral.java | 44 +++++++++---------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java index 7dc9ddcb3971efd..3c57c5e02057080 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java @@ -188,6 +188,9 @@ private static Expression processDateLikeTypeCoercion(ComparisonPredicate cp, Ex } else if (cp instanceof NullSafeEqual) { return BooleanLiteral.FALSE; } else if (cp instanceof GreaterThanEqual || cp instanceof LessThan) { + if (DateLiteral.isDateOutOfRange(((DateV2Literal) right).toJavaDateType().plusDays(1))) { + return BooleanLiteral.FALSE; + } right = ((DateV2Literal) right).plusDays(1); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java index a75bbf4c25b7596..4793b5727fc47de 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java @@ -211,28 +211,28 @@ static Result normalize(String s) { final String currentString = s; return Result.err( () -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid") - ); - } - i = j; - partNumber += 1; - } else if (isPunctuation(c) || c == ' ' || c == 'T') { - i += 1; - if (partNumber < 3 && isPunctuation(c)) { - sb.append('-'); - } else if (partNumber == 3) { - while (i < s.length() && (isPunctuation(s.charAt(i)) || s.charAt(i) == ' ' || s.charAt(i) == 'T')) { - i += 1; + ); } - // avoid add blank before zone-id, for example 2008-08-08 +08:00 - // should be normalized to 2008-08-08+08:00 - if (i >= s.length() || Character.isDigit(s.charAt(i))) { - sb.append(' '); - } - } else if (partNumber > 3 && isPunctuation(c)) { - sb.append(':'); - } else { - final String currentString = s; - return Result.err( + i = j; + partNumber += 1; + } else if (isPunctuation(c) || c == ' ' || c == 'T') { + i += 1; + if (partNumber < 3 && isPunctuation(c)) { + sb.append('-'); + } else if (partNumber == 3) { + while (i < s.length() && (isPunctuation(s.charAt(i)) || s.charAt(i) == ' ' || s.charAt(i) == 'T')) { + i += 1; + } + // avoid add blank before zone-id, for example 2008-08-08 +08:00 + // should be normalized to 2008-08-08+08:00 + if (i >= s.length() || Character.isDigit(s.charAt(i))) { + sb.append(' '); + } + } else if (partNumber > 3 && isPunctuation(c)) { + sb.append(':'); + } else { + final String currentString = s; + return Result.err( () -> new AnalysisException("date/datetime literal [" + currentString + "] is invalid") ); } @@ -372,7 +372,7 @@ protected static boolean checkDate(long year, long month, long day) { return false; } - protected static boolean isDateOutOfRange(LocalDateTime dateTime) { + public static boolean isDateOutOfRange(LocalDateTime dateTime) { return dateTime == null || dateTime.isBefore(START_OF_A_DAY) || dateTime.isAfter(END_OF_A_DAY); }