[feature](Nereids) fold weeks_sub/add on fe (#25155)
support folding weeks_sub/add on fe
This commit is contained in:
@ -30,7 +30,7 @@ import java.time.temporal.ChronoUnit;
|
||||
|
||||
/**
|
||||
* executable function:
|
||||
* date_add/sub, years/months/days/hours/minutes/seconds_add/sub, datediff
|
||||
* date_add/sub, years/months/week/days/hours/minutes/seconds_add/sub, datediff
|
||||
*/
|
||||
public class DateTimeArithmetic {
|
||||
/**
|
||||
@ -125,6 +125,29 @@ public class DateTimeArithmetic {
|
||||
return date.plusMonths(month.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* datetime arithmetic function weeks-add.
|
||||
*/
|
||||
@ExecFunction(name = "weeks_add", argTypes = {"DATE", "INT"}, returnType = "DATE")
|
||||
public static Expression weeksAdd(DateLiteral date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(weeks.getValue());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weeks_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
|
||||
public static Expression weeksAdd(DateTimeLiteral date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(weeks.getValue());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weeks_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
|
||||
public static Expression weeksAdd(DateV2Literal date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(weeks.getValue());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weeks_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
|
||||
public static Expression weeksAdd(DateTimeV2Literal date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(weeks.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* datetime arithmetic function days-add.
|
||||
*/
|
||||
@ -241,6 +264,29 @@ public class DateTimeArithmetic {
|
||||
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* datetime arithmetic function weeks-sub.
|
||||
*/
|
||||
@ExecFunction(name = "weeks_sub", argTypes = {"DATE", "INT"}, returnType = "DATE")
|
||||
public static Expression weeksSub(DateLiteral date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(-weeks.getValue());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weeks_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
|
||||
public static Expression weeksSub(DateTimeLiteral date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(-weeks.getValue());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weeks_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
|
||||
public static Expression weeksSub(DateV2Literal date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(-weeks.getValue());
|
||||
}
|
||||
|
||||
@ExecFunction(name = "weeks_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
|
||||
public static Expression weeksSub(DateTimeV2Literal date, IntegerLiteral weeks) {
|
||||
return date.plusWeeks(-weeks.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* datetime arithmetic function days-sub
|
||||
*/
|
||||
|
||||
@ -345,6 +345,11 @@ public class DateLiteral extends Literal {
|
||||
DateUtils.getTime(StandardDateFormat.DATE_FORMATTER, getStringValue()).plusMonths(months));
|
||||
}
|
||||
|
||||
public Expression plusWeeks(long weeks) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_FORMATTER, getStringValue()).plusWeeks(weeks));
|
||||
}
|
||||
|
||||
public Expression plusYears(long years) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_FORMATTER, getStringValue()).plusYears(years));
|
||||
|
||||
@ -209,6 +209,11 @@ public class DateTimeLiteral extends DateLiteral {
|
||||
DateUtils.getTime(StandardDateFormat.DATE_TIME_FORMATTER, getStringValue()).plusMonths(months));
|
||||
}
|
||||
|
||||
public Expression plusWeeks(long weeks) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_TIME_FORMATTER, getStringValue()).plusWeeks(weeks));
|
||||
}
|
||||
|
||||
public Expression plusDays(long days) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_TIME_FORMATTER, getStringValue()).plusDays(days));
|
||||
|
||||
@ -120,6 +120,13 @@ public class DateTimeV2Literal extends DateTimeLiteral {
|
||||
.plusMonths(months), getDataType().getScale());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression plusWeeks(long weeks) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
|
||||
.plusWeeks(weeks), getDataType().getScale());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression plusDays(long days) {
|
||||
return fromJavaDateType(
|
||||
|
||||
@ -60,6 +60,11 @@ public class DateV2Literal extends DateLiteral {
|
||||
DateUtils.getTime(StandardDateFormat.DATE_FORMATTER, getStringValue()).plusMonths(months));
|
||||
}
|
||||
|
||||
public Expression plusWeeks(long weeks) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_FORMATTER, getStringValue()).plusWeeks(weeks));
|
||||
}
|
||||
|
||||
public Expression plusYears(long years) {
|
||||
return fromJavaDateType(
|
||||
DateUtils.getTime(StandardDateFormat.DATE_FORMATTER, getStringValue()).plusYears(years));
|
||||
|
||||
Reference in New Issue
Block a user