From 632670a49c2eb28790510c52d8f5630f141e9c28 Mon Sep 17 00:00:00 2001 From: Pxl Date: Sun, 16 Oct 2022 14:31:26 +0800 Subject: [PATCH] [Enhancement](function) refactor of date function (#13362) refactor of date function --- .../format/parquet/vparquet_page_reader.cpp | 1 + be/src/vec/functions/date_time_transforms.h | 242 +++++++----------- .../function_date_or_datetime_to_something.h | 3 +- .../function_date_or_datetime_to_string.cpp | 16 +- .../function_date_or_datetime_to_string.h | 4 +- be/src/vec/functions/time_of_function.cpp | 59 ++--- be/src/vec/functions/to_time_function.cpp | 115 +++------ be/src/vec/runtime/vdatetime_value.cpp | 7 +- be/src/vec/runtime/vdatetime_value.h | 32 ++- tools/tpch-tools/queries/q9.sql | 2 +- 10 files changed, 188 insertions(+), 293 deletions(-) diff --git a/be/src/vec/exec/format/parquet/vparquet_page_reader.cpp b/be/src/vec/exec/format/parquet/vparquet_page_reader.cpp index 00e2ef0926..cd018f4107 100644 --- a/be/src/vec/exec/format/parquet/vparquet_page_reader.cpp +++ b/be/src/vec/exec/format/parquet/vparquet_page_reader.cpp @@ -19,6 +19,7 @@ #include +#include "common/config.h" #include "util/thrift_util.h" namespace doris::vectorized { diff --git a/be/src/vec/functions/date_time_transforms.h b/be/src/vec/functions/date_time_transforms.h index 8255713221..5fca7b1ce3 100644 --- a/be/src/vec/functions/date_time_transforms.h +++ b/be/src/vec/functions/date_time_transforms.h @@ -34,27 +34,20 @@ namespace doris::vectorized { -#define TIME_FUNCTION_IMPL(CLASS, UNIT, FUNCTION) \ - template \ - struct CLASS { \ - using ARG_TYPE = ArgType; \ - static constexpr auto name = #UNIT; \ - \ - static inline auto execute(const ARG_TYPE& t, bool& is_null) { \ - const auto& date_time_value = (DateValueType&)(t); \ - is_null = !date_time_value.is_valid_date(); \ - return date_time_value.FUNCTION; \ - } \ - \ - static DataTypes get_variadic_argument_types() { \ - if constexpr (std::is_same_v) { \ - return {std::make_shared()}; \ - } else if constexpr (std::is_same_v>) { \ - return {std::make_shared()}; \ - } else { \ - return {std::make_shared()}; \ - } \ - } \ +#define TIME_FUNCTION_IMPL(CLASS, UNIT, FUNCTION) \ + template \ + struct CLASS { \ + using OpArgType = ArgType; \ + static constexpr auto name = #UNIT; \ + \ + static inline auto execute(const ArgType& t) { \ + const auto& date_time_value = (typename DateTraits::T&)(t); \ + return date_time_value.FUNCTION; \ + } \ + \ + static DataTypes get_variadic_argument_types() { \ + return {std::make_shared::DateType>()}; \ + } \ } #define TO_TIME_FUNCTION(CLASS, UNIT) TIME_FUNCTION_IMPL(CLASS, UNIT, UNIT()) @@ -75,63 +68,50 @@ TIME_FUNCTION_IMPL(WeekDayImpl, weekday, weekday()); // TODO: the method should be always not nullable TIME_FUNCTION_IMPL(ToDaysImpl, to_days, daynr()); -#define TIME_FUNCTION_ONE_ARG_IMPL(CLASS, UNIT, FUNCTION) \ - template \ - struct CLASS { \ - using ARG_TYPE = ArgType; \ - static constexpr auto name = #UNIT; \ - \ - static inline auto execute(const ARG_TYPE& t, bool& is_null) { \ - const auto& date_time_value = (DateValueType&)(t); \ - is_null = !date_time_value.is_valid_date(); \ - return date_time_value.FUNCTION; \ - } \ - \ - static DataTypes get_variadic_argument_types() { \ - if constexpr (std::is_same_v) { \ - return {std::make_shared()}; \ - } else if constexpr (std::is_same_v>) { \ - return {std::make_shared()}; \ - } else { \ - return {std::make_shared()}; \ - } \ - } \ +#define TIME_FUNCTION_ONE_ARG_IMPL(CLASS, UNIT, FUNCTION) \ + template \ + struct CLASS { \ + using OpArgType = ArgType; \ + static constexpr auto name = #UNIT; \ + \ + static inline auto execute(const ArgType& t) { \ + const auto& date_time_value = (typename DateTraits::T&)(t); \ + return date_time_value.FUNCTION; \ + } \ + \ + static DataTypes get_variadic_argument_types() { \ + return {std::make_shared::DateType>()}; \ + } \ } TIME_FUNCTION_ONE_ARG_IMPL(ToWeekOneArgImpl, week, week(mysql_week_mode(0))); TIME_FUNCTION_ONE_ARG_IMPL(ToYearWeekOneArgImpl, yearweek, year_week(mysql_week_mode(0))); -template +template struct ToDateImpl { - using ARG_TYPE = ArgType; + using OpArgType = ArgType; + using T = typename DateTraits::T; static constexpr auto name = "to_date"; - static inline auto execute(const ArgType& t, bool& is_null) { - auto dt = binary_cast(t); - is_null = !dt.is_valid_date(); - if constexpr (std::is_same_v>) { - return binary_cast(dt); - } else if constexpr (std::is_same_v) { + static inline auto execute(const ArgType& t) { + auto dt = binary_cast(t); + if constexpr (std::is_same_v>) { + return binary_cast(dt); + } else if constexpr (std::is_same_v) { dt.cast_to_date(); - return binary_cast(dt); + return binary_cast(dt); } else { - return (UInt32)(binary_cast(dt) >> TIME_PART_LENGTH); + return (UInt32)(binary_cast(dt) >> TIME_PART_LENGTH); } } static DataTypes get_variadic_argument_types() { - if constexpr (std::is_same_v) { - return {std::make_shared()}; - } else if constexpr (std::is_same_v>) { - return {std::make_shared()}; - } else { - return {std::make_shared()}; - } + return {std::make_shared::DateType>()}; } }; -template -struct DateImpl : public ToDateImpl { +template +struct DateImpl : public ToDateImpl { static constexpr auto name = "date"; }; @@ -139,23 +119,22 @@ struct DateImpl : public ToDateImpl { // this function template struct TimeStampImpl { - using ARG_TYPE = ArgType; + using OpArgType = ArgType; static constexpr auto name = "timestamp"; - static inline auto execute(const ARG_TYPE& t, bool& is_null) { return t; } + static inline auto execute(const OpArgType& t) { return t; } }; -template +template struct DayNameImpl { - using ARG_TYPE = ArgType; + using OpArgType = ArgType; static constexpr auto name = "dayname"; static constexpr auto max_size = MAX_DAY_NAME_LEN; - static inline auto execute(const DateValueType& dt, ColumnString::Chars& res_data, - size_t& offset, bool& is_null) { + static inline auto execute(const typename DateTraits::T& dt, + ColumnString::Chars& res_data, size_t& offset) { const auto* day_name = dt.day_name(); - is_null = !dt.is_valid_date(); - if (day_name != nullptr && !is_null) { + if (day_name != nullptr) { auto len = strlen(day_name); memcpy(&res_data[offset], day_name, len); offset += len; @@ -164,27 +143,20 @@ struct DayNameImpl { } static DataTypes get_variadic_argument_types() { - if constexpr (std::is_same_v) { - return {std::make_shared()}; - } else if constexpr (std::is_same_v>) { - return {std::make_shared()}; - } else { - return {std::make_shared()}; - } + return {std::make_shared::DateType>()}; } }; -template +template struct MonthNameImpl { - using ARG_TYPE = ArgType; + using OpArgType = ArgType; static constexpr auto name = "monthname"; static constexpr auto max_size = MAX_MONTH_NAME_LEN; - static inline auto execute(const DateValueType& dt, ColumnString::Chars& res_data, - size_t& offset, bool& is_null) { + static inline auto execute(const typename DateTraits::T& dt, + ColumnString::Chars& res_data, size_t& offset) { const auto* month_name = dt.month_name(); - is_null = !dt.is_valid_date(); - if (month_name != nullptr && !is_null) { + if (month_name != nullptr) { auto len = strlen(month_name); memcpy(&res_data[offset], month_name, len); offset += len; @@ -193,13 +165,7 @@ struct MonthNameImpl { } static DataTypes get_variadic_argument_types() { - if constexpr (std::is_same_v) { - return {std::make_shared()}; - } else if constexpr (std::is_same_v>) { - return {std::make_shared()}; - } else { - return {std::make_shared()}; - } + return {std::make_shared::DateType>()}; } }; @@ -227,25 +193,11 @@ struct DateFormatImpl { } static DataTypes get_variadic_argument_types() { - if constexpr (std::is_same_v) { - return std::vector { - std::dynamic_pointer_cast( - std::make_shared()), - std::dynamic_pointer_cast( - std::make_shared())}; - } else if constexpr (std::is_same_v>) { - return std::vector { - std::dynamic_pointer_cast( - std::make_shared()), - std::dynamic_pointer_cast( - std::make_shared())}; - } else { - return std::vector { - std::dynamic_pointer_cast( - std::make_shared()), - std::dynamic_pointer_cast( - std::make_shared())}; - } + return std::vector { + std::dynamic_pointer_cast( + std::make_shared::DateType>()), + std::dynamic_pointer_cast( + std::make_shared())}; } }; @@ -280,52 +232,22 @@ struct FromUnixTimeImpl { template struct TransformerToStringOneArgument { - static void vector(const PaddedPODArray& ts, ColumnString::Chars& res_data, - ColumnString::Offsets& res_offsets, NullMap& null_map) { + static void vector(const PaddedPODArray& ts, + ColumnString::Chars& res_data, ColumnString::Offsets& res_offsets, + NullMap& null_map) { const auto len = ts.size(); res_data.resize(len * Transform::max_size); res_offsets.resize(len); - null_map.resize_fill(len, false); - - size_t offset = 0; - for (int i = 0; i < len; ++i) { - const auto& t = ts[i]; - const auto& date_time_value = reinterpret_cast(t); - res_offsets[i] = Transform::execute(date_time_value, res_data, offset, - reinterpret_cast(null_map[i])); - } - } - - static void vector(const PaddedPODArray& ts, ColumnString::Chars& res_data, - ColumnString::Offsets& res_offsets, NullMap& null_map) { - const auto len = ts.size(); - res_data.resize(len * Transform::max_size); - res_offsets.resize(len); - null_map.resize_fill(len, false); - - size_t offset = 0; - for (int i = 0; i < len; ++i) { - const auto& t = ts[i]; - const auto& date_time_value = reinterpret_cast&>(t); - res_offsets[i] = Transform::execute(date_time_value, res_data, offset, - reinterpret_cast(null_map[i])); - } - } - - static void vector(const PaddedPODArray& ts, ColumnString::Chars& res_data, - ColumnString::Offsets& res_offsets, NullMap& null_map) { - const auto len = ts.size(); - res_data.resize(len * Transform::max_size); - res_offsets.resize(len); - null_map.resize_fill(len, false); + null_map.resize(len); size_t offset = 0; for (int i = 0; i < len; ++i) { const auto& t = ts[i]; const auto& date_time_value = - reinterpret_cast&>(t); - res_offsets[i] = Transform::execute(date_time_value, res_data, offset, - reinterpret_cast(null_map[i])); + reinterpret_cast::T&>( + t); + res_offsets[i] = Transform::execute(date_time_value, res_data, offset); + null_map[i] = !date_time_value.is_valid_date(); } } }; @@ -359,10 +281,34 @@ struct Transformer { NullMap& null_map) { size_t size = vec_from.size(); vec_to.resize(size); - null_map.resize_fill(size, false); + null_map.resize(size); for (size_t i = 0; i < size; ++i) { - vec_to[i] = Transform::execute(vec_from[i], reinterpret_cast(null_map[i])); + vec_to[i] = Transform::execute(vec_from[i]); + null_map[i] = !((typename DateTraits::T&)(vec_from[i])) + .is_valid_date(); + } + } +}; + +template +struct Transformer> { + static void vector(const PaddedPODArray& vec_from, PaddedPODArray& vec_to, + NullMap& null_map) { + size_t size = vec_from.size(); + vec_to.resize(size); + null_map.resize(size); + + auto* __restrict to_ptr = vec_to.data(); + auto* __restrict from_ptr = vec_from.data(); + auto* __restrict null_map_ptr = null_map.data(); + + for (size_t i = 0; i < size; ++i) { + to_ptr[i] = ToYearImpl::execute(from_ptr[i]); + } + + for (size_t i = 0; i < size; ++i) { + null_map_ptr[i] = to_ptr[i] <= MIN_YEAR || to_ptr[i] >= MAX_YEAR; } } }; diff --git a/be/src/vec/functions/function_date_or_datetime_to_something.h b/be/src/vec/functions/function_date_or_datetime_to_something.h index 0762855fb2..dfac38dd97 100644 --- a/be/src/vec/functions/function_date_or_datetime_to_something.h +++ b/be/src/vec/functions/function_date_or_datetime_to_something.h @@ -21,7 +21,6 @@ #pragma once #include "vec/data_types/data_type_date.h" -#include "vec/data_types/data_type_date_time.h" #include "vec/functions/date_time_transforms.h" #include "vec/functions/function.h" @@ -91,7 +90,7 @@ public: Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, size_t result, size_t input_rows_count) override { - return DateTimeTransformImpl::execute(block, arguments, result, input_rows_count); } diff --git a/be/src/vec/functions/function_date_or_datetime_to_string.cpp b/be/src/vec/functions/function_date_or_datetime_to_string.cpp index 374f38a90e..cf215cd14d 100644 --- a/be/src/vec/functions/function_date_or_datetime_to_string.cpp +++ b/be/src/vec/functions/function_date_or_datetime_to_string.cpp @@ -24,17 +24,13 @@ namespace doris::vectorized { -using FunctionDayName = FunctionDateOrDateTimeToString>; -using FunctionDayNameV2 = - FunctionDateOrDateTimeToString, UInt32>>; -using FunctionMonthName = FunctionDateOrDateTimeToString>; -using FunctionMonthNameV2 = - FunctionDateOrDateTimeToString, UInt32>>; +using FunctionDayName = FunctionDateOrDateTimeToString>; +using FunctionDayNameV2 = FunctionDateOrDateTimeToString>; +using FunctionMonthName = FunctionDateOrDateTimeToString>; +using FunctionMonthNameV2 = FunctionDateOrDateTimeToString>; -using FunctionDateTimeV2DayName = - FunctionDateOrDateTimeToString, UInt64>>; -using FunctionDateTimeV2MonthName = - FunctionDateOrDateTimeToString, UInt64>>; +using FunctionDateTimeV2DayName = FunctionDateOrDateTimeToString>; +using FunctionDateTimeV2MonthName = FunctionDateOrDateTimeToString>; void register_function_date_time_to_string(SimpleFunctionFactory& factory) { factory.register_function(); diff --git a/be/src/vec/functions/function_date_or_datetime_to_string.h b/be/src/vec/functions/function_date_or_datetime_to_string.h index b4f2b80175..f540fbe229 100644 --- a/be/src/vec/functions/function_date_or_datetime_to_string.h +++ b/be/src/vec/functions/function_date_or_datetime_to_string.h @@ -20,8 +20,6 @@ #pragma once -#include "vec/data_types/data_type_date.h" -#include "vec/data_types/data_type_date_time.h" #include "vec/data_types/data_type_string.h" #include "vec/functions/date_time_transforms.h" #include "vec/functions/function.h" @@ -58,7 +56,7 @@ public: size_t result, size_t input_rows_count) override { const ColumnPtr source_col = block.get_by_position(arguments[0]).column; const auto* sources = - check_and_get_column>(source_col.get()); + check_and_get_column>(source_col.get()); auto col_res = ColumnString::create(); auto null_map = ColumnVector::create(); // Support all input of datetime is valind to make sure not null return diff --git a/be/src/vec/functions/time_of_function.cpp b/be/src/vec/functions/time_of_function.cpp index 42b0b8c198..e2e4b29625 100644 --- a/be/src/vec/functions/time_of_function.cpp +++ b/be/src/vec/functions/time_of_function.cpp @@ -22,54 +22,35 @@ namespace doris::vectorized { -using FunctionWeekOfYear = - FunctionDateOrDateTimeToSomething>; +using FunctionWeekOfYear = FunctionDateOrDateTimeToSomething>; using FunctionWeekOfYearV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionDayOfYear = - FunctionDateOrDateTimeToSomething>; -using FunctionDayOfYearV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionDayOfWeek = - FunctionDateOrDateTimeToSomething>; -using FunctionDayOfWeekV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionDayOfMonth = - FunctionDateOrDateTimeToSomething>; + FunctionDateOrDateTimeToSomething>; +using FunctionDayOfYear = FunctionDateOrDateTimeToSomething>; +using FunctionDayOfYearV2 = FunctionDateOrDateTimeToSomething>; +using FunctionDayOfWeek = FunctionDateOrDateTimeToSomething>; +using FunctionDayOfWeekV2 = FunctionDateOrDateTimeToSomething>; +using FunctionDayOfMonth = FunctionDateOrDateTimeToSomething>; using FunctionDayOfMonthV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; + FunctionDateOrDateTimeToSomething>; using FunctionYearWeek = - FunctionDateOrDateTimeToSomething>; -using FunctionYearWeekV2 = FunctionDateOrDateTimeToSomething< - DataTypeInt32, ToYearWeekOneArgImpl, UInt32>>; -using FunctionWeekDay = - FunctionDateOrDateTimeToSomething>; -using FunctionWeekDayV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; + FunctionDateOrDateTimeToSomething>; +using FunctionYearWeekV2 = + FunctionDateOrDateTimeToSomething>; +using FunctionWeekDay = FunctionDateOrDateTimeToSomething>; +using FunctionWeekDayV2 = FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2WeekOfYear = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2DayOfYear = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2DayOfWeek = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2DayOfMonth = - FunctionDateOrDateTimeToSomething, UInt64>>; -using FunctionDateTimeV2YearWeek = FunctionDateOrDateTimeToSomething< - DataTypeInt32, ToYearWeekOneArgImpl, UInt64>>; + FunctionDateOrDateTimeToSomething>; +using FunctionDateTimeV2YearWeek = + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2WeekDay = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; void register_function_time_of_function(SimpleFunctionFactory& factory) { factory.register_function(); diff --git a/be/src/vec/functions/to_time_function.cpp b/be/src/vec/functions/to_time_function.cpp index d3ee548fc9..5fce870e23 100644 --- a/be/src/vec/functions/to_time_function.cpp +++ b/be/src/vec/functions/to_time_function.cpp @@ -23,94 +23,47 @@ namespace doris::vectorized { -using FunctionYear = - FunctionDateOrDateTimeToSomething>; -using FunctionYearV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionQuarter = - FunctionDateOrDateTimeToSomething>; -using FunctionQuarterV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionMonth = - FunctionDateOrDateTimeToSomething>; -using FunctionMonthV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionDay = - FunctionDateOrDateTimeToSomething>; -using FunctionDayV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionWeek = - FunctionDateOrDateTimeToSomething>; -using FunctionWeekV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionHour = - FunctionDateOrDateTimeToSomething>; -using FunctionHourV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionMinute = - FunctionDateOrDateTimeToSomething>; -using FunctionMinuteV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionSecond = - FunctionDateOrDateTimeToSomething>; -using FunctionSecondV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionToDays = - FunctionDateOrDateTimeToSomething>; -using FunctionToDaysV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionToDate = - FunctionDateOrDateTimeToSomething>; -using FunctionToDateV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; -using FunctionDate = - FunctionDateOrDateTimeToSomething>; -using FunctionDateV2 = - FunctionDateOrDateTimeToSomething, UInt32>>; +using FunctionYear = FunctionDateOrDateTimeToSomething>; +using FunctionYearV2 = FunctionDateOrDateTimeToSomething>; +using FunctionQuarter = FunctionDateOrDateTimeToSomething>; +using FunctionQuarterV2 = FunctionDateOrDateTimeToSomething>; +using FunctionMonth = FunctionDateOrDateTimeToSomething>; +using FunctionMonthV2 = FunctionDateOrDateTimeToSomething>; +using FunctionDay = FunctionDateOrDateTimeToSomething>; +using FunctionDayV2 = FunctionDateOrDateTimeToSomething>; +using FunctionWeek = FunctionDateOrDateTimeToSomething>; +using FunctionWeekV2 = FunctionDateOrDateTimeToSomething>; +using FunctionHour = FunctionDateOrDateTimeToSomething>; +using FunctionHourV2 = FunctionDateOrDateTimeToSomething>; +using FunctionMinute = FunctionDateOrDateTimeToSomething>; +using FunctionMinuteV2 = FunctionDateOrDateTimeToSomething>; +using FunctionSecond = FunctionDateOrDateTimeToSomething>; +using FunctionSecondV2 = FunctionDateOrDateTimeToSomething>; +using FunctionToDays = FunctionDateOrDateTimeToSomething>; +using FunctionToDaysV2 = FunctionDateOrDateTimeToSomething>; +using FunctionToDate = FunctionDateOrDateTimeToSomething>; +using FunctionToDateV2 = FunctionDateOrDateTimeToSomething>; +using FunctionDate = FunctionDateOrDateTimeToSomething>; +using FunctionDateV2 = FunctionDateOrDateTimeToSomething>; -using FunctionDateTimeV2Year = - FunctionDateOrDateTimeToSomething, UInt64>>; +using FunctionDateTimeV2Year = FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2Quarter = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2Month = - FunctionDateOrDateTimeToSomething, UInt64>>; -using FunctionDateTimeV2Day = - FunctionDateOrDateTimeToSomething, UInt64>>; -using FunctionDateTimeV2Week = FunctionDateOrDateTimeToSomething< - DataTypeInt32, ToWeekOneArgImpl, UInt64>>; -using FunctionDateTimeV2Hour = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; +using FunctionDateTimeV2Day = FunctionDateOrDateTimeToSomething>; +using FunctionDateTimeV2Week = + FunctionDateOrDateTimeToSomething>; +using FunctionDateTimeV2Hour = FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2Minute = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2Second = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2ToDays = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; using FunctionDateTimeV2ToDate = - FunctionDateOrDateTimeToSomething, UInt64>>; -using FunctionDateTimeV2Date = - FunctionDateOrDateTimeToSomething, UInt64>>; + FunctionDateOrDateTimeToSomething>; +using FunctionDateTimeV2Date = FunctionDateOrDateTimeToSomething>; using FunctionTimeStamp = FunctionDateOrDateTimeToSomething>; diff --git a/be/src/vec/runtime/vdatetime_value.cpp b/be/src/vec/runtime/vdatetime_value.cpp index 28ecf960f2..1458349e0c 100644 --- a/be/src/vec/runtime/vdatetime_value.cpp +++ b/be/src/vec/runtime/vdatetime_value.cpp @@ -25,17 +25,18 @@ #include #include +#include "common/config.h" #include "runtime/datetime_value.h" #include "util/timezone_utils.h" namespace doris::vectorized { -static int s_days_in_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +static constexpr int s_days_in_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static const char* s_ab_month_name[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL}; + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", nullptr}; -static const char* s_ab_day_name[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", NULL}; +static const char* s_ab_day_name[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", nullptr}; uint8_t mysql_week_mode(uint32_t mode) { mode &= 7; diff --git a/be/src/vec/runtime/vdatetime_value.h b/be/src/vec/runtime/vdatetime_value.h index edf918d5fb..c40eefd8dd 100644 --- a/be/src/vec/runtime/vdatetime_value.h +++ b/be/src/vec/runtime/vdatetime_value.h @@ -15,8 +15,7 @@ // specific language governing permissions and limitations // under the License. -#ifndef DORIS_BE_RUNTIME_VDATETIME_VALUE_H -#define DORIS_BE_RUNTIME_VDATETIME_VALUE_H +#pragma once #include #include @@ -25,9 +24,7 @@ #include #include -#include "cctz/civil_time.h" #include "cctz/time_zone.h" -#include "common/config.h" #include "udf/udf.h" #include "util/hash_util.hpp" #include "util/time_lut.h" @@ -1457,6 +1454,31 @@ int64_t datetime_diff(const VecDateTimeValue& ts_value1, const DateV2Value& t return 0; } +class DataTypeDateTime; +class DataTypeDateV2; +class DataTypeDateTimeV2; + +template +struct DateTraits {}; + +template <> +struct DateTraits { + using T = VecDateTimeValue; + using DateType = DataTypeDateTime; +}; + +template <> +struct DateTraits { + using T = DateV2Value; + using DateType = DataTypeDateV2; +}; + +template <> +struct DateTraits { + using T = DateV2Value; + using DateType = DataTypeDateTimeV2; +}; + } // namespace vectorized } // namespace doris @@ -1484,5 +1506,3 @@ struct hash