From 9ed7b479b14472f2b5aa1e80e8769c851ce911bf Mon Sep 17 00:00:00 2001 From: englefly Date: Thu, 28 Sep 2023 12:00:26 +0800 Subject: [PATCH] make datelikeType length safe --- .../doris/nereids/types/coercion/DateLikeType.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java index eca9170157b3370..c32e0ef7c3eb33d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java @@ -27,6 +27,7 @@ import org.apache.doris.nereids.types.DateType; import org.apache.doris.nereids.types.DateV2Type; +import java.time.DateTimeException; import java.time.LocalDate; import java.time.temporal.ChronoUnit; @@ -49,11 +50,15 @@ public double rangeLength(double high, double low) { return 0; } if (Double.isInfinite(high) || Double.isInfinite(low)) { - return high - low; + return Double.POSITIVE_INFINITY; + } + try { + LocalDate to = toLocalDate(high); + LocalDate from = toLocalDate(low); + return ChronoUnit.DAYS.between(from, to); + } catch (DateTimeException e) { + return Double.POSITIVE_INFINITY; } - LocalDate to = toLocalDate(high); - LocalDate from = toLocalDate(low); - return ChronoUnit.DAYS.between(from, to); } /**