This is an automated email from the ASF dual-hosted git repository.
jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new ebe582758f [opt](Nereids): use LocalDate to replace Calendar (#24361)
ebe582758f is described below
commit ebe582758fa5fbddab01de5557f345edc1d9c4df
Author: jakevin <[email protected]>
AuthorDate: Sun Sep 17 11:16:03 2023 +0800
[opt](Nereids): use LocalDate to replace Calendar (#24361)
---
.../doris/nereids/types/coercion/DateLikeType.java | 24 ++++++++++++----------
1 file changed, 13 insertions(+), 11 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 ff728a73ac..eca9170157 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,31 +27,33 @@ import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DateType;
import org.apache.doris.nereids.types.DateV2Type;
+import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
-import java.util.Calendar;
/**
* date like type.
*/
public abstract class DateLikeType extends PrimitiveType {
- private Calendar toCalendar(double d) {
- //d = (year * 10000 + month * 100 + day) * 1000000L;
+ private LocalDate toLocalDate(double d) {
+ // d = (year * 10000 + month * 100 + day) * 1000000L;
int date = (int) (d / 1000000);
int day = date % 100;
int month = (date / 100) % 100;
int year = date / 10000;
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.YEAR, year);
- calendar.set(Calendar.MONTH, month);
- calendar.set(Calendar.DAY_OF_MONTH, day);
- return calendar;
+ return LocalDate.of(year, month, day);
}
@Override
public double rangeLength(double high, double low) {
- Calendar to = toCalendar(high);
- Calendar from = toCalendar(low);
- return ChronoUnit.DAYS.between(from.toInstant(), to.toInstant());
+ if (high == low) {
+ return 0;
+ }
+ if (Double.isInfinite(high) || Double.isInfinite(low)) {
+ return high - low;
+ }
+ LocalDate to = toLocalDate(high);
+ LocalDate from = toLocalDate(low);
+ return ChronoUnit.DAYS.between(from, to);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]