Skip to content

Commit b5b09c2

Browse files
authored
[Enhancement](func) Add fold constant for PREVIOUS_DAY (#60755)
Related PR: #60680
1 parent 8356299 commit b5b09c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,20 @@ public static Expression nextDay(DateV2Literal date, StringLiteral day) {
12921292
return date.plusDays(daysToAdd);
12931293
}
12941294

1295+
/**
1296+
* date arithmetic function previous_day
1297+
*/
1298+
@ExecFunction(name = "previous_day")
1299+
public static Expression previousDay(DateV2Literal date, StringLiteral day) {
1300+
int dayOfWeek = getDayOfWeek(day.getValue());
1301+
if (dayOfWeek == 0) {
1302+
throw new RuntimeException("Invalid day of week: " + day.getValue());
1303+
}
1304+
int daysToSub = (date.getDayOfWeek() - dayOfWeek + 7) % 7;
1305+
daysToSub = daysToSub == 0 ? 7 : daysToSub;
1306+
return date.plusDays(-daysToSub);
1307+
}
1308+
12951309
/**
12961310
* date transform function sec_to_time
12971311
*/

0 commit comments

Comments
 (0)