From 632f7a3d3d2a96b9310581e8ba5b9eb2ca1af635 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 1 Jun 2022 14:47:37 +0800 Subject: [PATCH] [Feature] add `weekday` function on vectorized engine (#9901) --- be/src/vec/functions/date_time_transforms.h | 1 + be/src/vec/functions/time_of_function.cpp | 2 ++ be/test/vec/function/function_time_test.cpp | 23 +++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/be/src/vec/functions/date_time_transforms.h b/be/src/vec/functions/date_time_transforms.h index b148746490..7381a96885 100644 --- a/be/src/vec/functions/date_time_transforms.h +++ b/be/src/vec/functions/date_time_transforms.h @@ -57,6 +57,7 @@ TIME_FUNCTION_IMPL(WeekOfYearImpl, weekofyear, week(mysql_week_mode(3))); TIME_FUNCTION_IMPL(DayOfYearImpl, dayofyear, day_of_year()); TIME_FUNCTION_IMPL(DayOfMonthImpl, dayofmonth, day()); TIME_FUNCTION_IMPL(DayOfWeekImpl, dayofweek, day_of_week()); +TIME_FUNCTION_IMPL(WeekDayImpl, weekday, weekday()); // TODO: the method should be always not nullable TIME_FUNCTION_IMPL(ToDaysImpl, to_days, daynr()); diff --git a/be/src/vec/functions/time_of_function.cpp b/be/src/vec/functions/time_of_function.cpp index 1d364f528d..071704826d 100644 --- a/be/src/vec/functions/time_of_function.cpp +++ b/be/src/vec/functions/time_of_function.cpp @@ -27,6 +27,7 @@ using FunctionDayOfYear = FunctionDateOrDateTimeToSomething; using FunctionDayOfMonth = FunctionDateOrDateTimeToSomething; using FunctionYearWeek = FunctionDateOrDateTimeToSomething; +using FunctionWeekDay = FunctionDateOrDateTimeToSomething; void register_function_time_of_function(SimpleFunctionFactory& factory) { factory.register_function(); @@ -34,5 +35,6 @@ void register_function_time_of_function(SimpleFunctionFactory& factory) { factory.register_function(); factory.register_function(); factory.register_function(); + factory.register_function(); } } // namespace doris::vectorized \ No newline at end of file diff --git a/be/test/vec/function/function_time_test.cpp b/be/test/vec/function/function_time_test.cpp index c7c3c98755..c046ee825a 100644 --- a/be/test/vec/function/function_time_test.cpp +++ b/be/test/vec/function/function_time_test.cpp @@ -543,4 +543,27 @@ TEST(VTimestampFunctionsTest, convert_tz_test) { check_function(func_name, input_types, data_set); } + +TEST(VTimestampFunctionsTest, weekday_test) { + std::string func_name = "weekday"; + + { + InputTypeSet input_types = {TypeIndex::DateTime}; + + DataSet data_set = {{{std::string("2001-02-03 12:34:56")}, 5}, + {{std::string("2019-06-25")}, 1}, + {{std::string("2020-00-01 00:00:00")}, Null()}, + {{std::string("2020-01-00 00:00:00")}, Null()}}; + + check_function(func_name, input_types, data_set); + } + InputTypeSet input_types = {TypeIndex::Date}; + + DataSet data_set = {{{std::string("2001-02-03")}, 5}, + {{std::string("2019-06-25")}, 1}, + {{std::string("2020-00-01")}, Null()}, + {{std::string("2020-01-00")}, Null()}}; + + check_function(func_name, input_types, data_set); +} } // namespace doris::vectorized