From b6011ff2e2b5d4b2198896fd00b2473023700d56 Mon Sep 17 00:00:00 2001 From: MitchellGale-BitQuill <104795536+MitchellGale-BitQuill@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:20:15 -0700 Subject: [PATCH] Changed function resolved to default --- .../expression/datetime/DateTimeFunction.java | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java index b5c305a7b5..d074777045 100644 --- a/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java +++ b/core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java @@ -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; @@ -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), @@ -221,7 +222,7 @@ private FunctionResolver add_date(FunctionName functionName) { ); } - private FunctionResolver adddate() { + private DefaultFunctionResolver adddate() { return add_date(BuiltinFunctionName.ADDDATE.getName()); } @@ -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), @@ -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), @@ -268,7 +269,7 @@ private FunctionResolver datetime() { ); } - private FunctionResolver date_add() { + private DefaultFunctionResolver date_add() { return add_date(BuiltinFunctionName.DATE_ADD.getName()); } @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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)); } @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -472,7 +473,7 @@ private FunctionResolver second() { ); } - private FunctionResolver subdate() { + private DefaultFunctionResolver subdate() { return sub_date(BuiltinFunctionName.SUBDATE.getName()); } @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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), @@ -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. */ @@ -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. */