[Enhancement](func) Add fold constant for PREVIOUS_DAY (#60755)

Related PR: https://github.com/apache/doris/pull/60680
This commit is contained in:
linrrarity authored and GitHub committed 2026-02-14 17:13:59 +08:00
1 parent 83562990ff
commit b5b09c2469
1 file changed
+14
@@ -1292,6 +1292,20 @@ public class DateTimeExtractAndTransform {
return date.plusDays(daysToAdd);
}
/**
* date arithmetic function previous_day
*/
@ExecFunction(name = "previous_day")
public static Expression previousDay(DateV2Literal date, StringLiteral day) {
int dayOfWeek = getDayOfWeek(day.getValue());
if (dayOfWeek == 0) {
throw new RuntimeException("Invalid day of week: " + day.getValue());
}
int daysToSub = (date.getDayOfWeek() - dayOfWeek + 7) % 7;
daysToSub = daysToSub == 0 ? 7 : daysToSub;
return date.plusDays(-daysToSub);
}
/**
* date transform function sec_to_time
*/