[fix](nereids)prevent null pointer exception if datetime value overflows (#39675)

pick from master https://github.com/apache/doris/pull/39482
This commit is contained in:
starocean999
2024-08-21 14:17:34 +08:00
committed by GitHub
parent 0bfcee1251
commit ba3b56d269
4 changed files with 58 additions and 10 deletions

View File

@ -346,9 +346,10 @@ public class SimplifyComparisonPredicate extends AbstractExpressionRewriteRule i
private static Expression migrateToDateV2(DateTimeLiteral l, AdjustType type) {
DateV2Literal d = new DateV2Literal(l.getYear(), l.getMonth(), l.getDay());
if (type == AdjustType.UPPER && (l.getHour() != 0 || l.getMinute() != 0 || l.getSecond() != 0)) {
d = ((DateV2Literal) d.plusDays(1));
return d.plusDays(1);
} else {
return d;
}
return d;
}
private static Expression migrateToDate(DateV2Literal l) {

View File

@ -104,23 +104,34 @@ public class TimeRoundSeries {
if (getCeil) {
step = step + (deltaInsidePeriod == 0 ? 0 : period);
}
Expression result = null;
switch (tag) {
case YEAR:
return ((DateTimeLiteral) start.plusYears(step)).toJavaDateType();
result = start.plusYears(step);
break;
case MONTH:
return ((DateTimeLiteral) start.plusMonths(step)).toJavaDateType();
result = start.plusMonths(step);
break;
case DAY:
return ((DateTimeLiteral) start.plusDays(step)).toJavaDateType();
result = start.plusDays(step);
break;
case HOUR:
return ((DateTimeLiteral) start.plusHours(step)).toJavaDateType();
result = start.plusHours(step);
break;
case MINUTE:
return ((DateTimeLiteral) start.plusMinutes(step)).toJavaDateType();
result = start.plusMinutes(step);
break;
case SECOND:
return ((DateTimeLiteral) start.plusSeconds(step)).toJavaDateType();
result = start.plusSeconds(step);
break;
default:
break;
}
return null;
if (result != null && result instanceof DateTimeLiteral) {
return ((DateTimeLiteral) result).toJavaDateType();
} else {
return null;
}
}
/**

View File

@ -336,7 +336,7 @@ public class DateLiteral extends Literal {
}
protected static boolean isDateOutOfRange(LocalDateTime dateTime) {
return dateTime.isBefore(START_OF_A_DAY) || dateTime.isAfter(END_OF_A_DAY);
return dateTime == null || dateTime.isBefore(START_OF_A_DAY) || dateTime.isAfter(END_OF_A_DAY);
}
private boolean checkDatetime(TemporalAccessor dateTime) {