Skip to content

Commit

Permalink
make datelikeType length safe
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Sep 28, 2023
1 parent c4fe501 commit 9ed7b47
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 9ed7b47

Please sign in to comment.