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/06 12:25:31 UTC

[GitHub] [doris] lsy3993 opened a new pull request, #13132: [function](date function) add new date function 'first_month_day'

lsy3993 opened a new pull request, #13132:
URL: https://github.com/apache/doris/pull/13132

   # Proposed changes
   
   Issue Number: close #13131
   
   ## Problem summary
   
   Describe your changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: 
       - [ ] Yes
       - [x] No
       - [ ] I don't know
   2. Has unit tests been added:
       - [x] Yes
       - [ ] No
       - [ ] No Need
   3. Has document been added or modified:
       - [x] Yes
       - [ ] No
       - [ ] No Need
   4. Does it need to update dependencies:
       - [ ] Yes
       - [x] No
   5. Are there any changes that cannot be rolled back:
       - [ ] Yes (If Yes, please explain WHY)
       - [x] No
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
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


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

Posted by GitBox <gi...@apache.org>.
Gabriel39 commented on code in PR #13132:
URL: https://github.com/apache/doris/pull/13132#discussion_r990718769


##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -478,6 +478,149 @@ class FunctionUnixTimestamp : public IFunction {
     }
 };
 
+template <typename Impl>
+class FirstMonthDay : public IFunction {
+public:
+    static constexpr auto name = "first_month_day";
+    static FunctionPtr create() { return std::make_shared<FirstMonthDay<Impl>>(); }
+
+    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; }
+
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
+        return Impl::get_return_type_impl(arguments);
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        return Impl::get_variadic_argument_types();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        return Impl::execute_impl(context, block, arguments, result, input_rows_count);
+    }
+};
+
+template <typename DateType>
+struct FirstMonthDayImpl {
+    static DataTypes get_variadic_argument_types() {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {
+            return {std::make_shared<DataTypeDate>()};
+        } else if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
+            return {std::make_shared<DataTypeDateV2>()};
+        } else {
+            return {std::make_shared<DataTypeDateTimeV2>()};
+        }
+    }
+
+    // input DateTime and Date, return Date
+    // input DateTimeV2 and DateV2, return DateV2
+    static DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {

Review Comment:
   If `DateType` is same as DataTypeDate, we also return DataTypeDate here



##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -478,6 +478,149 @@ class FunctionUnixTimestamp : public IFunction {
     }
 };
 
+template <typename Impl>
+class FirstMonthDay : public IFunction {
+public:
+    static constexpr auto name = "first_month_day";
+    static FunctionPtr create() { return std::make_shared<FirstMonthDay<Impl>>(); }
+
+    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; }
+
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
+        return Impl::get_return_type_impl(arguments);
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        return Impl::get_variadic_argument_types();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        return Impl::execute_impl(context, block, arguments, result, input_rows_count);
+    }
+};
+
+template <typename DateType>
+struct FirstMonthDayImpl {
+    static DataTypes get_variadic_argument_types() {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {

Review Comment:
   `DateType` is already a DataType, we can use it as an argument directly



-- 
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


[GitHub] [doris] lsy3993 commented on a diff in pull request #13132: [function](date function) add new date function 'first_month_day'

Posted by GitBox <gi...@apache.org>.
lsy3993 commented on code in PR #13132:
URL: https://github.com/apache/doris/pull/13132#discussion_r991017597


##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -478,6 +478,149 @@ class FunctionUnixTimestamp : public IFunction {
     }
 };
 
+template <typename Impl>
+class FirstMonthDay : public IFunction {
+public:
+    static constexpr auto name = "first_month_day";
+    static FunctionPtr create() { return std::make_shared<FirstMonthDay<Impl>>(); }
+
+    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; }
+
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
+        return Impl::get_return_type_impl(arguments);
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        return Impl::get_variadic_argument_types();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        return Impl::execute_impl(context, block, arguments, result, input_rows_count);
+    }
+};
+
+template <typename DateType>
+struct FirstMonthDayImpl {
+    static DataTypes get_variadic_argument_types() {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {
+            return {std::make_shared<DataTypeDate>()};
+        } else if constexpr (std::is_same_v<DateType, DataTypeDateV2>) {
+            return {std::make_shared<DataTypeDateV2>()};
+        } else {
+            return {std::make_shared<DataTypeDateTimeV2>()};
+        }
+    }
+
+    // input DateTime and Date, return Date
+    // input DateTimeV2 and DateV2, return DateV2
+    static DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) {
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {

Review Comment:
   return DataTypeDate when DateType is DataTypeDate



-- 
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


[GitHub] [doris] lsy3993 closed pull request #13132: [function](date function) add new date function 'first_month_day'

Posted by GitBox <gi...@apache.org>.
lsy3993 closed pull request #13132: [function](date function) add new date function 'first_month_day'
URL: https://github.com/apache/doris/pull/13132


-- 
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