You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/10/17 10:58:28 UTC

[GitHub] [doris] Gabriel39 commented on a diff in pull request #13400: [function](date function)add new date function 'last_day'

Gabriel39 commented on code in PR #13400:
URL: https://github.com/apache/doris/pull/13400#discussion_r996914151


##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -569,6 +569,164 @@ class FunctionUnixTimestamp : public IFunction {
     }
 };
 
+template <typename Impl, typename DateType>
+class FunctionDateOrDateTimeToDate : public IFunction {
+public:
+    static constexpr auto name = Impl::name;
+    static FunctionPtr create() {
+        return std::make_shared<FunctionDateOrDateTimeToDate<Impl, DateType>>();
+    }
+
+    String get_name() const override { return name; }
+
+    bool use_default_implementation_for_nulls() const override { return true; }

Review Comment:
   `use_default_implementation_for_constants` also need to override and set to true



##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -569,6 +569,164 @@ class FunctionUnixTimestamp : public IFunction {
     }
 };
 
+template <typename Impl, typename DateType>
+class FunctionDateOrDateTimeToDate : public IFunction {
+public:
+    static constexpr auto name = Impl::name;
+    static FunctionPtr create() {
+        return std::make_shared<FunctionDateOrDateTimeToDate<Impl, DateType>>();
+    }
+
+    String get_name() const override { return name; }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    bool is_variadic() const override { return true; }
+
+    // input DateTime and Date, return Date
+    // input DateTimeV2 and DateV2, return DateV2
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {

Review Comment:
   Use `or` to collapse these two conditions



##########
regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy:
##########
@@ -424,4 +424,30 @@ suite("test_date_function") {
     qt_sql """ select minutes_sub(test_time2,1) result from ${tableName}; """
     //seconds_sub
     qt_sql """ select seconds_sub(test_time2,1) result from ${tableName}; """
+
+    // test last_day
+    sql """ SET enable_vectorized_engine = TRUE; """

Review Comment:
   also add a case for row-based engine



##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -569,6 +569,164 @@ class FunctionUnixTimestamp : public IFunction {
     }
 };
 
+template <typename Impl, typename DateType>
+class FunctionDateOrDateTimeToDate : public IFunction {
+public:
+    static constexpr auto name = Impl::name;
+    static FunctionPtr create() {
+        return std::make_shared<FunctionDateOrDateTimeToDate<Impl, DateType>>();
+    }
+
+    String get_name() const override { return name; }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    bool is_variadic() const override { return true; }
+
+    // input DateTime and Date, return Date
+    // input DateTimeV2 and DateV2, return DateV2
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {
+            return make_nullable(std::make_shared<DataTypeDate>());
+        } else if constexpr (std::is_same_v<DateType, DataTypeDate>) {
+            return make_nullable(std::make_shared<DataTypeDate>());
+        } else if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
+            return make_nullable(std::make_shared<DataTypeDateV2>());
+        } else {
+            return make_nullable(std::make_shared<DataTypeDateV2>());
+        }
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {

Review Comment:
   `DataTypeDate` is also possible as input argument



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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