This is an automated email from the ASF dual-hosted git repository. panxiaolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 632670a49c [Enhancement](function) refactor of date function (#13362) 632670a49c is described below commit 632670a49c2eb28790510c52d8f5630f141e9c28 Author: Pxl <pxl...@qq.com> AuthorDate: Sun Oct 16 14:31:26 2022 +0800 [Enhancement](function) refactor of date function (#13362) refactor of date function --- .../exec/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 <stdint.h> +#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 <typename DateValueType, typename ArgType> \ - 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<DateValueType, VecDateTimeValue>) { \ - return {std::make_shared<DataTypeDateTime>()}; \ - } else if constexpr (std::is_same_v<DateValueType, DateV2Value<DateV2ValueType>>) { \ - return {std::make_shared<DataTypeDateV2>()}; \ - } else { \ - return {std::make_shared<DataTypeDateTimeV2>()}; \ - } \ - } \ +#define TIME_FUNCTION_IMPL(CLASS, UNIT, FUNCTION) \ + template <typename ArgType> \ + struct CLASS { \ + using OpArgType = ArgType; \ + static constexpr auto name = #UNIT; \ + \ + static inline auto execute(const ArgType& t) { \ + const auto& date_time_value = (typename DateTraits<ArgType>::T&)(t); \ + return date_time_value.FUNCTION; \ + } \ + \ + static DataTypes get_variadic_argument_types() { \ + return {std::make_shared<typename DateTraits<ArgType>::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 <typename DateValueType, typename ArgType> \ - 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<DateValueType, VecDateTimeValue>) { \ - return {std::make_shared<DataTypeDateTime>()}; \ - } else if constexpr (std::is_same_v<DateValueType, DateV2Value<DateV2ValueType>>) { \ - return {std::make_shared<DataTypeDateV2>()}; \ - } else { \ - return {std::make_shared<DataTypeDateTimeV2>()}; \ - } \ - } \ +#define TIME_FUNCTION_ONE_ARG_IMPL(CLASS, UNIT, FUNCTION) \ + template <typename ArgType> \ + struct CLASS { \ + using OpArgType = ArgType; \ + static constexpr auto name = #UNIT; \ + \ + static inline auto execute(const ArgType& t) { \ + const auto& date_time_value = (typename DateTraits<ArgType>::T&)(t); \ + return date_time_value.FUNCTION; \ + } \ + \ + static DataTypes get_variadic_argument_types() { \ + return {std::make_shared<typename DateTraits<ArgType>::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 <typename DateValueType, typename ArgType> +template <typename ArgType> struct ToDateImpl { - using ARG_TYPE = ArgType; + using OpArgType = ArgType; + using T = typename DateTraits<ArgType>::T; static constexpr auto name = "to_date"; - static inline auto execute(const ArgType& t, bool& is_null) { - auto dt = binary_cast<ArgType, DateValueType>(t); - is_null = !dt.is_valid_date(); - if constexpr (std::is_same_v<DateValueType, DateV2Value<DateV2ValueType>>) { - return binary_cast<DateValueType, ArgType>(dt); - } else if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { + static inline auto execute(const ArgType& t) { + auto dt = binary_cast<ArgType, T>(t); + if constexpr (std::is_same_v<T, DateV2Value<DateV2ValueType>>) { + return binary_cast<T, ArgType>(dt); + } else if constexpr (std::is_same_v<T, VecDateTimeValue>) { dt.cast_to_date(); - return binary_cast<DateValueType, ArgType>(dt); + return binary_cast<T, ArgType>(dt); } else { - return (UInt32)(binary_cast<DateValueType, ArgType>(dt) >> TIME_PART_LENGTH); + return (UInt32)(binary_cast<T, ArgType>(dt) >> TIME_PART_LENGTH); } } static DataTypes get_variadic_argument_types() { - if constexpr (std::is_same_v<DateValueType, VecDateTimeValue>) { - return {std::make_shared<DataTypeDateTime>()}; - } else if constexpr (std::is_same_v<DateValueType, DateV2Value<DateV2ValueType>>) { - return {std::make_shared<DataTypeDateV2>()}; - } else { - return {std::make_shared<DataTypeDateTimeV2>()}; - } + return {std::make_shared<typename DateTraits<ArgType>::DateType>()}; } }; -template <typename DateValue, typename ArgType> -struct DateImpl : public ToDateImpl<DateValue, ArgType> { +template <typename ArgType> +struct DateImpl : public ToDateImpl<ArgType> { static constexpr auto name = "date"; }; @@ -139,23 +119,22 @@ struct DateImpl : public ToDateImpl<DateValue, ArgType> { // this function template <typename ArgType> 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 <typename DateValueType, typename ArgType> +template <typename ArgType> 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<ArgType>::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<DateValueType, VecDateTimeValue>) { - return {std::make_shared<DataTypeDateTime>()}; - } else if constexpr (std::is_same_v<DateValueType, DateV2Value<DateV2ValueType>>) { - return {std::make_shared<DataTypeDateV2>()}; - } else { - return {std::make_shared<DataTypeDateTimeV2>()}; - } + return {std::make_shared<typename DateTraits<ArgType>::DateType>()}; } }; -template <typename DateValueType, typename ArgType> +template <typename ArgType> 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<ArgType>::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<DateValueType, VecDateTimeValue>) { - return {std::make_shared<DataTypeDateTime>()}; - } else if constexpr (std::is_same_v<DateValueType, DateV2Value<DateV2ValueType>>) { - return {std::make_shared<DataTypeDateV2>()}; - } else { - return {std::make_shared<DataTypeDateTimeV2>()}; - } + return {std::make_shared<typename DateTraits<ArgType>::DateType>()}; } }; @@ -227,25 +193,11 @@ struct DateFormatImpl { } static DataTypes get_variadic_argument_types() { - if constexpr (std::is_same_v<DateType, VecDateTimeValue>) { - return std::vector<DataTypePtr> { - std::dynamic_pointer_cast<const IDataType>( - std::make_shared<vectorized::DataTypeDateTime>()), - std::dynamic_pointer_cast<const IDataType>( - std::make_shared<vectorized::DataTypeString>())}; - } else if constexpr (std::is_same_v<DateType, DateV2Value<DateV2ValueType>>) { - return std::vector<DataTypePtr> { - std::dynamic_pointer_cast<const IDataType>( - std::make_shared<vectorized::DataTypeDateV2>()), - std::dynamic_pointer_cast<const IDataType>( - std::make_shared<vectorized::DataTypeString>())}; - } else { - return std::vector<DataTypePtr> { - std::dynamic_pointer_cast<const IDataType>( - std::make_shared<vectorized::DataTypeDateTimeV2>()), - std::dynamic_pointer_cast<const IDataType>( - std::make_shared<vectorized::DataTypeString>())}; - } + return std::vector<DataTypePtr> { + std::dynamic_pointer_cast<const IDataType>( + std::make_shared<typename DateTraits<ArgType>::DateType>()), + std::dynamic_pointer_cast<const IDataType>( + std::make_shared<vectorized::DataTypeString>())}; } }; @@ -280,52 +232,22 @@ struct FromUnixTimeImpl { template <typename Transform> struct TransformerToStringOneArgument { - static void vector(const PaddedPODArray<Int64>& 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<const VecDateTimeValue&>(t); - res_offsets[i] = Transform::execute(date_time_value, res_data, offset, - reinterpret_cast<bool&>(null_map[i])); - } - } - - static void vector(const PaddedPODArray<UInt32>& 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<const DateV2Value<DateV2ValueType>&>(t); - res_offsets[i] = Transform::execute(date_time_value, res_data, offset, - reinterpret_cast<bool&>(null_map[i])); - } - } - - static void vector(const PaddedPODArray<UInt64>& ts, ColumnString::Chars& res_data, - ColumnString::Offsets& res_offsets, NullMap& null_map) { + static void vector(const PaddedPODArray<typename Transform::OpArgType>& 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<const DateV2Value<DateTimeV2ValueType>&>(t); - res_offsets[i] = Transform::execute(date_time_value, res_data, offset, - reinterpret_cast<bool&>(null_map[i])); + reinterpret_cast<const typename DateTraits<typename Transform::OpArgType>::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]); + null_map[i] = !((typename DateTraits<typename Transform::OpArgType>::T&)(vec_from[i])) + .is_valid_date(); + } + } +}; + +template <typename FromType, typename ToType> +struct Transformer<FromType, ToType, ToYearImpl<FromType>> { + static void vector(const PaddedPODArray<FromType>& vec_from, PaddedPODArray<ToType>& 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<FromType>::execute(from_ptr[i]); + } for (size_t i = 0; i < size; ++i) { - vec_to[i] = Transform::execute(vec_from[i], reinterpret_cast<bool&>(null_map[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<typename Transform::ARG_TYPE, typename ToDataType::FieldType, + return DateTimeTransformImpl<typename Transform::OpArgType, typename ToDataType::FieldType, Transform>::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<DayNameImpl<VecDateTimeValue, Int64>>; -using FunctionDayNameV2 = - FunctionDateOrDateTimeToString<DayNameImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionMonthName = FunctionDateOrDateTimeToString<MonthNameImpl<VecDateTimeValue, Int64>>; -using FunctionMonthNameV2 = - FunctionDateOrDateTimeToString<MonthNameImpl<DateV2Value<DateV2ValueType>, UInt32>>; +using FunctionDayName = FunctionDateOrDateTimeToString<DayNameImpl<Int64>>; +using FunctionDayNameV2 = FunctionDateOrDateTimeToString<DayNameImpl<UInt32>>; +using FunctionMonthName = FunctionDateOrDateTimeToString<MonthNameImpl<Int64>>; +using FunctionMonthNameV2 = FunctionDateOrDateTimeToString<MonthNameImpl<UInt32>>; -using FunctionDateTimeV2DayName = - FunctionDateOrDateTimeToString<DayNameImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; -using FunctionDateTimeV2MonthName = - FunctionDateOrDateTimeToString<MonthNameImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; +using FunctionDateTimeV2DayName = FunctionDateOrDateTimeToString<DayNameImpl<UInt64>>; +using FunctionDateTimeV2MonthName = FunctionDateOrDateTimeToString<MonthNameImpl<UInt64>>; void register_function_date_time_to_string(SimpleFunctionFactory& factory) { factory.register_function<FunctionDayName>(); 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<ColumnVector<typename Transform::ARG_TYPE>>(source_col.get()); + check_and_get_column<ColumnVector<typename Transform::OpArgType>>(source_col.get()); auto col_res = ColumnString::create(); auto null_map = ColumnVector<UInt8>::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<DataTypeInt32, WeekOfYearImpl<VecDateTimeValue, Int64>>; +using FunctionWeekOfYear = FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekOfYearImpl<Int64>>; using FunctionWeekOfYearV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - WeekOfYearImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionDayOfYear = - FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfYearImpl<VecDateTimeValue, Int64>>; -using FunctionDayOfYearV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - DayOfYearImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionDayOfWeek = - FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfWeekImpl<VecDateTimeValue, Int64>>; -using FunctionDayOfWeekV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - DayOfWeekImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionDayOfMonth = - FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfMonthImpl<VecDateTimeValue, Int64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekOfYearImpl<UInt32>>; +using FunctionDayOfYear = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfYearImpl<Int64>>; +using FunctionDayOfYearV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfYearImpl<UInt32>>; +using FunctionDayOfWeek = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfWeekImpl<Int64>>; +using FunctionDayOfWeekV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfWeekImpl<UInt32>>; +using FunctionDayOfMonth = FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfMonthImpl<Int64>>; using FunctionDayOfMonthV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - DayOfMonthImpl<DateV2Value<DateV2ValueType>, UInt32>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfMonthImpl<UInt32>>; using FunctionYearWeek = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToYearWeekOneArgImpl<VecDateTimeValue, Int64>>; -using FunctionYearWeekV2 = FunctionDateOrDateTimeToSomething< - DataTypeInt32, ToYearWeekOneArgImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionWeekDay = - FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekDayImpl<VecDateTimeValue, Int64>>; -using FunctionWeekDayV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - WeekDayImpl<DateV2Value<DateV2ValueType>, UInt32>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearWeekOneArgImpl<Int64>>; +using FunctionYearWeekV2 = + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearWeekOneArgImpl<UInt32>>; +using FunctionWeekDay = FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekDayImpl<Int64>>; +using FunctionWeekDayV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekDayImpl<UInt32>>; using FunctionDateTimeV2WeekOfYear = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - WeekOfYearImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekOfYearImpl<UInt64>>; using FunctionDateTimeV2DayOfYear = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - DayOfYearImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfYearImpl<UInt64>>; using FunctionDateTimeV2DayOfWeek = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - DayOfWeekImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfWeekImpl<UInt64>>; using FunctionDateTimeV2DayOfMonth = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - DayOfMonthImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; -using FunctionDateTimeV2YearWeek = FunctionDateOrDateTimeToSomething< - DataTypeInt32, ToYearWeekOneArgImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, DayOfMonthImpl<UInt64>>; +using FunctionDateTimeV2YearWeek = + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearWeekOneArgImpl<UInt64>>; using FunctionDateTimeV2WeekDay = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - WeekDayImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, WeekDayImpl<UInt64>>; void register_function_time_of_function(SimpleFunctionFactory& factory) { factory.register_function<FunctionDayOfWeek>(); 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<DataTypeInt32, ToYearImpl<VecDateTimeValue, Int64>>; -using FunctionYearV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToYearImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionQuarter = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToQuarterImpl<VecDateTimeValue, Int64>>; -using FunctionQuarterV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToQuarterImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionMonth = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMonthImpl<VecDateTimeValue, Int64>>; -using FunctionMonthV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToMonthImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionDay = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDayImpl<VecDateTimeValue, Int64>>; -using FunctionDayV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToDayImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionWeek = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToWeekOneArgImpl<VecDateTimeValue, Int64>>; -using FunctionWeekV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToWeekOneArgImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionHour = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToHourImpl<VecDateTimeValue, Int64>>; -using FunctionHourV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToHourImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionMinute = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMinuteImpl<VecDateTimeValue, Int64>>; -using FunctionMinuteV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToMinuteImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionSecond = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToSecondImpl<VecDateTimeValue, Int64>>; -using FunctionSecondV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToSecondImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionToDays = - FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDaysImpl<VecDateTimeValue, Int64>>; -using FunctionToDaysV2 = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToDaysImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionToDate = - FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToDateImpl<VecDateTimeValue, Int64>>; -using FunctionToDateV2 = - FunctionDateOrDateTimeToSomething<DataTypeDateV2, - ToDateImpl<DateV2Value<DateV2ValueType>, UInt32>>; -using FunctionDate = - FunctionDateOrDateTimeToSomething<DataTypeDateTime, DateImpl<VecDateTimeValue, Int64>>; -using FunctionDateV2 = - FunctionDateOrDateTimeToSomething<DataTypeDateV2, - DateImpl<DateV2Value<DateV2ValueType>, UInt32>>; +using FunctionYear = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearImpl<Int64>>; +using FunctionYearV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearImpl<UInt32>>; +using FunctionQuarter = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToQuarterImpl<Int64>>; +using FunctionQuarterV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToQuarterImpl<UInt32>>; +using FunctionMonth = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMonthImpl<Int64>>; +using FunctionMonthV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMonthImpl<UInt32>>; +using FunctionDay = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDayImpl<Int64>>; +using FunctionDayV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDayImpl<UInt32>>; +using FunctionWeek = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToWeekOneArgImpl<Int64>>; +using FunctionWeekV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToWeekOneArgImpl<UInt32>>; +using FunctionHour = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToHourImpl<Int64>>; +using FunctionHourV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToHourImpl<UInt32>>; +using FunctionMinute = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMinuteImpl<Int64>>; +using FunctionMinuteV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMinuteImpl<UInt32>>; +using FunctionSecond = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToSecondImpl<Int64>>; +using FunctionSecondV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToSecondImpl<UInt32>>; +using FunctionToDays = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDaysImpl<Int64>>; +using FunctionToDaysV2 = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDaysImpl<UInt32>>; +using FunctionToDate = FunctionDateOrDateTimeToSomething<DataTypeDateTime, ToDateImpl<Int64>>; +using FunctionToDateV2 = FunctionDateOrDateTimeToSomething<DataTypeDateV2, ToDateImpl<UInt32>>; +using FunctionDate = FunctionDateOrDateTimeToSomething<DataTypeDateTime, DateImpl<Int64>>; +using FunctionDateV2 = FunctionDateOrDateTimeToSomething<DataTypeDateV2, DateImpl<UInt32>>; -using FunctionDateTimeV2Year = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToYearImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; +using FunctionDateTimeV2Year = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToYearImpl<UInt64>>; using FunctionDateTimeV2Quarter = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToQuarterImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToQuarterImpl<UInt64>>; using FunctionDateTimeV2Month = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToMonthImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; -using FunctionDateTimeV2Day = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToDayImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; -using FunctionDateTimeV2Week = FunctionDateOrDateTimeToSomething< - DataTypeInt32, ToWeekOneArgImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; -using FunctionDateTimeV2Hour = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToHourImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMonthImpl<UInt64>>; +using FunctionDateTimeV2Day = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDayImpl<UInt64>>; +using FunctionDateTimeV2Week = + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToWeekOneArgImpl<UInt64>>; +using FunctionDateTimeV2Hour = FunctionDateOrDateTimeToSomething<DataTypeInt32, ToHourImpl<UInt64>>; using FunctionDateTimeV2Minute = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToMinuteImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToMinuteImpl<UInt64>>; using FunctionDateTimeV2Second = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToSecondImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToSecondImpl<UInt64>>; using FunctionDateTimeV2ToDays = - FunctionDateOrDateTimeToSomething<DataTypeInt32, - ToDaysImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeInt32, ToDaysImpl<UInt64>>; using FunctionDateTimeV2ToDate = - FunctionDateOrDateTimeToSomething<DataTypeDateV2, - ToDateImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; -using FunctionDateTimeV2Date = - FunctionDateOrDateTimeToSomething<DataTypeDateV2, - DateImpl<DateV2Value<DateTimeV2ValueType>, UInt64>>; + FunctionDateOrDateTimeToSomething<DataTypeDateV2, ToDateImpl<UInt64>>; +using FunctionDateTimeV2Date = FunctionDateOrDateTimeToSomething<DataTypeDateV2, DateImpl<UInt64>>; using FunctionTimeStamp = FunctionDateOrDateTimeToSomething<DataTypeDateTime, TimeStampImpl<Int64>>; 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 <sstream> #include <valarray> +#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 <re2/re2.h> #include <stdint.h> @@ -25,9 +24,7 @@ #include <cstddef> #include <iostream> -#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>& t return 0; } +class DataTypeDateTime; +class DataTypeDateV2; +class DataTypeDateTimeV2; + +template <typename T> +struct DateTraits {}; + +template <> +struct DateTraits<int64_t> { + using T = VecDateTimeValue; + using DateType = DataTypeDateTime; +}; + +template <> +struct DateTraits<uint32_t> { + using T = DateV2Value<DateV2ValueType>; + using DateType = DataTypeDateV2; +}; + +template <> +struct DateTraits<uint64_t> { + using T = DateV2Value<DateTimeV2ValueType>; + using DateType = DataTypeDateTimeV2; +}; + } // namespace vectorized } // namespace doris @@ -1484,5 +1506,3 @@ struct hash<doris::vectorized::DateV2Value<doris::vectorized::DateTimeV2ValueTyp } }; } // namespace std - -#endif diff --git a/tools/tpch-tools/queries/q9.sql b/tools/tpch-tools/queries/q9.sql index 4960e8b67e..357813c6ca 100644 --- a/tools/tpch-tools/queries/q9.sql +++ b/tools/tpch-tools/queries/q9.sql @@ -17,7 +17,7 @@ -- Modified -select/*+SET_VAR(exec_mem_limit=17179869184, parallel_fragment_exec_instance_num=4, enable_vectorized_engine=true, batch_size=4096, disable_join_reorder=false, enable_cost_based_join_reorder=false, enable_projection=true, enable_remove_no_conjuncts_runtime_filter_policy=true, runtime_filter_wait_time_ms=10000) */ +select/*+SET_VAR(exec_mem_limit=37179869184, parallel_fragment_exec_instance_num=16, enable_vectorized_engine=true, batch_size=4096, disable_join_reorder=false, enable_cost_based_join_reorder=false, enable_projection=true, enable_remove_no_conjuncts_runtime_filter_policy=true, runtime_filter_wait_time_ms=10000) */ nation, o_year, sum(amount) as sum_profit --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org