Skip to content

Commit

Permalink
Changed function resolved to default
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellGale authored Sep 28, 2022
1 parent eb0c894 commit b6011ff
Showing 1 changed file with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.opensearch.sql.exception.ExpressionEvaluationException;
import org.opensearch.sql.expression.function.BuiltinFunctionName;
import org.opensearch.sql.expression.function.BuiltinFunctionRepository;
import org.opensearch.sql.expression.function.DefaultFunctionResolver;
import org.opensearch.sql.expression.function.FunctionName;
import org.opensearch.sql.expression.function.FunctionResolver;
import org.opensearch.sql.utils.DateTimeUtils;
Expand Down Expand Up @@ -205,7 +206,7 @@ private FunctionResolver current_date() {
* (STRING/DATETIME/TIMESTAMP, LONG) -> DATETIME
*/

private FunctionResolver add_date(FunctionName functionName) {
private DefaultFunctionResolver add_date(FunctionName functionName) {
return define(functionName,
impl(nullMissingHandling(DateTimeFunction::exprAddDateInterval),
DATETIME, STRING, INTERVAL),
Expand All @@ -221,7 +222,7 @@ private FunctionResolver add_date(FunctionName functionName) {
);
}

private FunctionResolver adddate() {
private DefaultFunctionResolver adddate() {
return add_date(BuiltinFunctionName.ADDDATE.getName());
}

Expand All @@ -231,7 +232,7 @@ private FunctionResolver adddate() {
* (DATETIME, STRING, STRING) -> DATETIME
* (STRING, STRING, STRING) -> DATETIME
*/
private FunctionResolver convert_tz() {
private DefaultFunctionResolver convert_tz() {
return define(BuiltinFunctionName.CONVERT_TZ.getName(),
impl(nullMissingHandling(DateTimeFunction::exprConvertTZ),
DATETIME, DATETIME, STRING, STRING),
Expand All @@ -245,7 +246,7 @@ private FunctionResolver convert_tz() {
* Also to construct a date type. The supported signatures:
* STRING/DATE/DATETIME/TIMESTAMP -> DATE
*/
private FunctionResolver date() {
private DefaultFunctionResolver date() {
return define(BuiltinFunctionName.DATE.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, STRING),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATE),
Expand All @@ -268,7 +269,7 @@ private FunctionResolver datetime() {
);
}

private FunctionResolver date_add() {
private DefaultFunctionResolver date_add() {
return add_date(BuiltinFunctionName.DATE_ADD.getName());
}

Expand All @@ -279,7 +280,7 @@ private FunctionResolver date_add() {
* (DATE, LONG) -> DATE
* (STRING/DATETIME/TIMESTAMP, LONG) -> DATETIME
*/
private FunctionResolver sub_date(FunctionName functionName) {
private DefaultFunctionResolver sub_date(FunctionName functionName) {
return define(functionName,
impl(nullMissingHandling(DateTimeFunction::exprSubDateInterval),
DATETIME, STRING, INTERVAL),
Expand All @@ -295,14 +296,14 @@ private FunctionResolver sub_date(FunctionName functionName) {
);
}

private FunctionResolver date_sub() {
private DefaultFunctionResolver date_sub() {
return sub_date(BuiltinFunctionName.DATE_SUB.getName());
}

/**
* DAY(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31).
*/
private FunctionResolver day() {
private DefaultFunctionResolver day() {
return define(BuiltinFunctionName.DAY.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME),
Expand All @@ -316,7 +317,7 @@ private FunctionResolver day() {
* return the name of the weekday for date, including Monday, Tuesday, Wednesday,
* Thursday, Friday, Saturday and Sunday.
*/
private FunctionResolver dayName() {
private DefaultFunctionResolver dayName() {
return define(BuiltinFunctionName.DAYNAME.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATE),
impl(nullMissingHandling(DateTimeFunction::exprDayName), STRING, DATETIME),
Expand All @@ -328,7 +329,7 @@ private FunctionResolver dayName() {
/**
* DAYOFMONTH(STRING/DATE/DATETIME/TIMESTAMP). return the day of the month (1-31).
*/
private FunctionResolver dayOfMonth() {
private DefaultFunctionResolver dayOfMonth() {
return define(BuiltinFunctionName.DAYOFMONTH.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprDayOfMonth), INTEGER, DATETIME),
Expand All @@ -341,7 +342,7 @@ private FunctionResolver dayOfMonth() {
* DAYOFWEEK(STRING/DATE/DATETIME/TIMESTAMP).
* return the weekday index for date (1 = Sunday, 2 = Monday, …, 7 = Saturday).
*/
private FunctionResolver dayOfWeek() {
private DefaultFunctionResolver dayOfWeek() {
return define(BuiltinFunctionName.DAYOFWEEK.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprDayOfWeek), INTEGER, DATETIME),
Expand All @@ -354,7 +355,7 @@ private FunctionResolver dayOfWeek() {
* DAYOFYEAR(STRING/DATE/DATETIME/TIMESTAMP).
* return the day of the year for date (1-366).
*/
private FunctionResolver dayOfYear() {
private DefaultFunctionResolver dayOfYear() {
return define(BuiltinFunctionName.DAYOFYEAR.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprDayOfYear), INTEGER, DATETIME),
Expand All @@ -366,7 +367,7 @@ private FunctionResolver dayOfYear() {
/**
* FROM_DAYS(LONG). return the date value given the day number N.
*/
private FunctionResolver from_days() {
private DefaultFunctionResolver from_days() {
return define(BuiltinFunctionName.FROM_DAYS.getName(),
impl(nullMissingHandling(DateTimeFunction::exprFromDays), DATE, LONG));
}
Expand All @@ -381,7 +382,7 @@ private FunctionResolver from_unixtime() {
/**
* HOUR(STRING/TIME/DATETIME/TIMESTAMP). return the hour value for time.
*/
private FunctionResolver hour() {
private DefaultFunctionResolver hour() {
return define(BuiltinFunctionName.HOUR.getName(),
impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprHour), INTEGER, TIME),
Expand All @@ -403,7 +404,7 @@ private FunctionResolver maketime() {
/**
* MICROSECOND(STRING/TIME/DATETIME/TIMESTAMP). return the microsecond value for time.
*/
private FunctionResolver microsecond() {
private DefaultFunctionResolver microsecond() {
return define(BuiltinFunctionName.MICROSECOND.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprMicrosecond), INTEGER, TIME),
Expand All @@ -415,7 +416,7 @@ private FunctionResolver microsecond() {
/**
* MINUTE(STRING/TIME/DATETIME/TIMESTAMP). return the minute value for time.
*/
private FunctionResolver minute() {
private DefaultFunctionResolver minute() {
return define(BuiltinFunctionName.MINUTE.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprMinute), INTEGER, TIME),
Expand All @@ -427,7 +428,7 @@ private FunctionResolver minute() {
/**
* MONTH(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-12).
*/
private FunctionResolver month() {
private DefaultFunctionResolver month() {
return define(BuiltinFunctionName.MONTH.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprMonth), INTEGER, DATETIME),
Expand All @@ -439,7 +440,7 @@ private FunctionResolver month() {
/**
* MONTHNAME(STRING/DATE/DATETIME/TIMESTAMP). return the full name of the month for date.
*/
private FunctionResolver monthName() {
private DefaultFunctionResolver monthName() {
return define(BuiltinFunctionName.MONTHNAME.getName(),
impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATE),
impl(nullMissingHandling(DateTimeFunction::exprMonthName), STRING, DATETIME),
Expand All @@ -451,7 +452,7 @@ private FunctionResolver monthName() {
/**
* QUARTER(STRING/DATE/DATETIME/TIMESTAMP). return the month for date (1-4).
*/
private FunctionResolver quarter() {
private DefaultFunctionResolver quarter() {
return define(BuiltinFunctionName.QUARTER.getName(),
impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprQuarter), INTEGER, DATETIME),
Expand All @@ -463,7 +464,7 @@ private FunctionResolver quarter() {
/**
* SECOND(STRING/TIME/DATETIME/TIMESTAMP). return the second value for time.
*/
private FunctionResolver second() {
private DefaultFunctionResolver second() {
return define(BuiltinFunctionName.SECOND.getName(),
impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, STRING),
impl(nullMissingHandling(DateTimeFunction::exprSecond), INTEGER, TIME),
Expand All @@ -472,7 +473,7 @@ private FunctionResolver second() {
);
}

private FunctionResolver subdate() {
private DefaultFunctionResolver subdate() {
return sub_date(BuiltinFunctionName.SUBDATE.getName());
}

Expand All @@ -481,7 +482,7 @@ private FunctionResolver subdate() {
* Also to construct a time type. The supported signatures:
* STRING/DATE/DATETIME/TIME/TIMESTAMP -> TIME
*/
private FunctionResolver time() {
private DefaultFunctionResolver time() {
return define(BuiltinFunctionName.TIME.getName(),
impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, STRING),
impl(nullMissingHandling(DateTimeFunction::exprTime), TIME, DATE),
Expand All @@ -493,7 +494,7 @@ private FunctionResolver time() {
/**
* TIME_TO_SEC(STRING/TIME/DATETIME/TIMESTAMP). return the time argument, converted to seconds.
*/
private FunctionResolver time_to_sec() {
private DefaultFunctionResolver time_to_sec() {
return define(BuiltinFunctionName.TIME_TO_SEC.getName(),
impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, STRING),
impl(nullMissingHandling(DateTimeFunction::exprTimeToSec), LONG, TIME),
Expand All @@ -507,7 +508,7 @@ private FunctionResolver time_to_sec() {
* Also to construct a date type. The supported signatures:
* STRING/DATE/DATETIME/TIMESTAMP -> DATE
*/
private FunctionResolver timestamp() {
private DefaultFunctionResolver timestamp() {
return define(BuiltinFunctionName.TIMESTAMP.getName(),
impl(nullMissingHandling(DateTimeFunction::exprTimestamp), TIMESTAMP, STRING),
impl(nullMissingHandling(DateTimeFunction::exprTimestamp), TIMESTAMP, DATE),
Expand All @@ -518,7 +519,7 @@ private FunctionResolver timestamp() {
/**
* TO_DAYS(STRING/DATE/DATETIME/TIMESTAMP). return the day number of the given date.
*/
private FunctionResolver to_days() {
private DefaultFunctionResolver to_days() {
return define(BuiltinFunctionName.TO_DAYS.getName(),
impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, STRING),
impl(nullMissingHandling(DateTimeFunction::exprToDays), LONG, TIMESTAMP),
Expand All @@ -539,7 +540,7 @@ private FunctionResolver unix_timestamp() {
/**
* WEEK(DATE[,mode]). return the week number for date.
*/
private FunctionResolver week() {
private DefaultFunctionResolver week() {
return define(BuiltinFunctionName.WEEK.getName(),
impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprWeekWithoutMode), INTEGER, DATETIME),
Expand All @@ -555,7 +556,7 @@ private FunctionResolver week() {
/**
* YEAR(STRING/DATE/DATETIME/TIMESTAMP). return the year for date (1000-9999).
*/
private FunctionResolver year() {
private DefaultFunctionResolver year() {
return define(BuiltinFunctionName.YEAR.getName(),
impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATE),
impl(nullMissingHandling(DateTimeFunction::exprYear), INTEGER, DATETIME),
Expand All @@ -572,7 +573,7 @@ private FunctionResolver year() {
* (DATETIME, STRING) -> STRING
* (TIMESTAMP, STRING) -> STRING
*/
private FunctionResolver date_format() {
private DefaultFunctionResolver date_format() {
return define(BuiltinFunctionName.DATE_FORMAT.getName(),
impl(nullMissingHandling(DateTimeFormatterUtil::getFormattedDate),
STRING, STRING, STRING),
Expand Down Expand Up @@ -990,6 +991,7 @@ private ExprValue exprToDays(ExprValue date) {

/**
* Week for date implementation for ExprValue.
*
* @param date ExprValue of Date/Datetime/Timestamp/String type.
* @param mode ExprValue of Integer type.
*/
Expand Down Expand Up @@ -1074,6 +1076,7 @@ private Double unixTimeStampOfImpl(ExprValue value) {
/**
* Week for date implementation for ExprValue.
* When mode is not specified default value mode 0 is used for default_week_format.
*
* @param date ExprValue of Date/Datetime/Timestamp/String type.
* @return ExprValue.
*/
Expand Down

0 comments on commit b6011ff

Please sign in to comment.