HappenLee commented on code in PR #13039: URL: https://github.com/apache/doris/pull/13039#discussion_r984146930
########## be/src/vec/functions/function_timestamp.cpp: ########## @@ -214,6 +234,90 @@ struct MakeDateImpl { } }; +template <typename DateValueType, typename ArgType> +struct DateTrunc { + static constexpr auto name = "date_trunc"; + + static bool is_variadic() { return true; } + + static DataTypes get_variadic_argument_types() { + if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { + return {std::make_shared<DataTypeDateTime>(), std::make_shared<DataTypeString>()}; + } else { + return {std::make_shared<DataTypeDateTimeV2>(), std::make_shared<DataTypeString>()}; + } + } + + static DataTypePtr get_return_type_impl(const DataTypes& arguments) { + if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { + return make_nullable(std::make_shared<DataTypeDateTime>()); + } else { + return make_nullable(std::make_shared<DataTypeDateTimeV2>()); + } + } + + static Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, + size_t result, size_t input_rows_count) { + DCHECK_EQ(arguments.size(), 2); + ColumnPtr argument_columns[2]; + auto null_map = ColumnUInt8::create(input_rows_count, 0); + argument_columns[0] = + block.get_by_position(arguments[0]).column->convert_to_full_column_if_const(); + argument_columns[1] = + block.get_by_position(arguments[1]).column->convert_to_full_column_if_const(); + auto datetime_column = static_cast<const ColumnVector<ArgType>*>(argument_columns[0].get()); + auto str_column = static_cast<const ColumnString*>(argument_columns[1].get()); + auto& rdata = str_column->get_chars(); + auto& roffsets = str_column->get_offsets(); + + ColumnPtr res = nullptr; + + if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { Review Comment: res = ColumnVector<ArgType>::create(); executeImpl(datetime_column->get_data(), rdata, roffsets, static_cast<ColumnVector<ArgType>*>(res->assume_mutable().get())->get_data(), null_map->get_data(), input_rows_count); -- 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