mirror of
https://github.com/apache/doris.git
synced 2026-11-04 07:31:17 +00:00
[Enhancement](func) Add fold constant for PREVIOUS_DAY (#60755)
Related PR: https://github.com/apache/doris/pull/60680
This commit is contained in:
1 parent
83562990ff
commit
b5b09c2469
1 file changed
+14
+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
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user