Skip to content

Commit ee2dcc6

Browse files
linrrzqqqYour Name
authored andcommitted
[Enhancement](func) Add fold constant for PREVIOUS_DAY (#60755)
Related PR: #60680
1 parent 427091c commit ee2dcc6

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
@@ -1206,6 +1206,20 @@ public static Expression nextDay(DateV2Literal date, StringLiteral day) {
12061206
return date.plusDays(daysToAdd);
12071207
}
12081208

1209+
/**
1210+
* date arithmetic function previous_day
1211+
*/
1212+
@ExecFunction(name = "previous_day")
1213+
public static Expression previousDay(DateV2Literal date, StringLiteral day) {
1214+
int dayOfWeek = getDayOfWeek(day.getValue());
1215+
if (dayOfWeek == 0) {
1216+
throw new RuntimeException("Invalid day of week: " + day.getValue());
1217+
}
1218+
int daysToSub = (date.getDayOfWeek() - dayOfWeek + 7) % 7;
1219+
daysToSub = daysToSub == 0 ? 7 : daysToSub;
1220+
return date.plusDays(-daysToSub);
1221+
}
1222+
12091223
/**
12101224
* date transform function sec_to_time
12111225
*/

0 commit comments

Comments
 (0)