Skip to content

Commit 1062346

Browse files
jackwenerpull[bot]
authored andcommitted
[performance](Nereids): avoid use getStringValue() in getTimeFormatter() (#27625)
Original `getTimeFormatter()` will convert `long` to `string`, and then parse `string` to `int`.
1 parent 30d6d5a commit 1062346

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,25 +1094,17 @@ private int getOrDefault(final TemporalAccessor accessor, final ChronoField fiel
10941094
}
10951095

10961096
public LocalDateTime getTimeFormatter() {
1097-
TemporalAccessor accessor;
10981097
if (type.equals(Type.DATE) || type.equals(Type.DATEV2)) {
1099-
accessor = DATE_FORMATTER.parse(getStringValue());
1098+
return LocalDateTime.of((int) this.year, (int) this.month, (int) this.day, 0, 0, 0);
11001099
} else if (type.isDatetimeV2()) {
1101-
accessor = DATE_TIME_FORMATTER_TO_MICRO_SECOND.parse(getStringValue());
1100+
return LocalDateTime.of((int) this.year, (int) this.month, (int) this.day, (int) this.hour,
1101+
(int) this.minute,
1102+
(int) this.second, (int) this.microsecond * 1000);
11021103
} else {
1103-
accessor = DATE_TIME_FORMATTER.parse(getStringValue());
1104+
return LocalDateTime.of((int) this.year, (int) this.month, (int) this.day, (int) this.hour,
1105+
(int) this.minute,
1106+
(int) this.second);
11041107
}
1105-
final int year = accessor.get(ChronoField.YEAR);
1106-
final int month = accessor.get(ChronoField.MONTH_OF_YEAR);
1107-
final int dayOfMonth = accessor.get(ChronoField.DAY_OF_MONTH);
1108-
final int hour = getOrDefault(accessor, ChronoField.HOUR_OF_DAY, 0);
1109-
final int minute = getOrDefault(accessor, ChronoField.MINUTE_OF_HOUR, 0);
1110-
final int second = getOrDefault(accessor, ChronoField.SECOND_OF_MINUTE, 0);
1111-
final int microSeconds = getOrDefault(accessor, ChronoField.MICRO_OF_SECOND, 0);
1112-
1113-
// LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute,
1114-
// int second, int nanoOfSecond)
1115-
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, microSeconds * 1000);
11161108
}
11171109

11181110
public DateLiteral plusYears(long year) throws AnalysisException {

0 commit comments

Comments
 (0)