You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/06/01 15:29:16 UTC

[incubator-doris] 21/22: [Feature] add `weekday` function on vectorized engine (#9901)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch dev-1.0.1
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git

commit 03748e4b17a9fafcce8b26a5f6ea59e5229909fd
Author: Gabriel <ga...@gmail.com>
AuthorDate: Wed Jun 1 14:47:37 2022 +0800

    [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 7640a2707d..ef54798025 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<DataTypeInt32, DayOf
 using FunctionDayOfWeek = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfWeekImpl>;
 using FunctionDayOfMonth = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfMonthImpl>;
 using FunctionYearWeek = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearWeekOneArgImpl>;
+using FunctionWeekDay = FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekDayImpl>;
 
 void register_function_time_of_function(SimpleFunctionFactory& factory) {
     factory.register_function<FunctionDayOfWeek>();
@@ -34,5 +35,6 @@ void register_function_time_of_function(SimpleFunctionFactory& factory) {
     factory.register_function<FunctionDayOfYear>();
     factory.register_function<FunctionWeekOfYear>();
     factory.register_function<FunctionYearWeek>();
+    factory.register_function<FunctionWeekDay>();
 }
 } // 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 7e45295c4d..70841072e6 100644
--- a/be/test/vec/function/function_time_test.cpp
+++ b/be/test/vec/function/function_time_test.cpp
@@ -551,6 +551,29 @@ TEST(TimestampFunctionsTest, convert_tz_test) {
 
     check_function<DataTypeDate, true>(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<DataTypeInt32, true>(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<DataTypeInt32, true>(func_name, input_types, data_set);
+}
 } // namespace doris::vectorized
 
 int main(int argc, char** argv) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org