lsy3993 commented on code in PR #13466:
URL: https://github.com/apache/doris/pull/13466#discussion_r1000096388


##########
be/src/vec/functions/function_timestamp.cpp:
##########
@@ -569,6 +569,151 @@ 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; }
+
+    bool use_default_implementation_for_constants() 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> ||
+                      std::is_same_v<DateType, DataTypeDate>) {
+            return make_nullable(std::make_shared<DataTypeDate>());
+        } else {
+            return make_nullable(std::make_shared<DataTypeDateV2>());
+        }
+    }
+
+    DataTypes get_variadic_argument_types_impl() const override {
+        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>()};
+        }
+    }
+
+    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 LastDayImpl {
+    static constexpr auto name = "last_day";
+
+    static Status execute_impl(FunctionContext* context, Block& block,
+                               const ColumnNumbers& arguments, size_t result,
+                               size_t input_rows_count) {
+        auto null_map = ColumnUInt8::create(input_rows_count, 0);
+        ColumnPtr res_column;
+        ColumnPtr argument_column =
+                
block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        if constexpr (std::is_same_v<DateType, DataTypeDateTime>) {

Review Comment:
   Use DataTypeDateTime there can solve both date and datetime, why we should 
add 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-unsubscr...@doris.apache.org

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


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

Reply via email to