Replace enable_date32_results by enable_extended_results_for_datetime_functions

This commit is contained in:
Roman Vasin 2022-09-15 12:48:09 +00:00
parent 3346d8e27b
commit 563449779c
9 changed files with 52 additions and 52 deletions

View File

@ -3144,7 +3144,7 @@ Result:
└─────┴─────┴───────┘
```
## enable_date32_results {#enable-date32-results}
## enable_extended_results_for_datetime_functions {#enable-extended-results-for-datetime-functions}
Enables or disables returning results of type Date32 for functions toStartOfYear, toStartOfISOYear, toStartOfQuarter, toStartOfMonth, toStartOfWeek, toMonday and toLastDayOfMonth.

View File

@ -3799,7 +3799,7 @@ Exception: Total regexp lengths too large.
Значение по умолчанию: `1`.
## enable_date32_results {#enable-date32-results}
## enable_extended_results_for_datetime_functions {#enable-extended-results-for-datetime-functions}
Включает и отключает возвращение результатов типа Date32 для функций toStartOfYear, toStartOfISOYear, toStartOfQuarter, toStartOfMonth, toStartOfWeek, toMonday и toLastDayOfMonth

View File

@ -136,7 +136,7 @@ static constexpr UInt64 operator""_GiB(unsigned long long value)
M(Bool, distributed_aggregation_memory_efficient, true, "Is the memory-saving mode of distributed aggregation enabled.", 0) \
M(UInt64, aggregation_memory_efficient_merge_threads, 0, "Number of threads to use for merge intermediate aggregation results in memory efficient mode. When bigger, then more memory is consumed. 0 means - same as 'max_threads'.", 0) \
M(Bool, enable_positional_arguments, true, "Enable positional arguments in ORDER BY, GROUP BY and LIMIT BY", 0) \
M(Bool, enable_date32_results, false, "Enable functions like toLastDayOfMonth to return Date32.", 0) \
M(Bool, enable_extended_results_for_datetime_functions, false, "Enable Date functions like toLastDayOfMonth return Date32 results (instead of Date results) for Date32/DateTime64 arguments.", 0) \
\
M(Bool, group_by_use_nulls, false, "Treat columns mentioned in ROLLUP, CUBE or GROUPING SETS as Nullable", 0) \
\

View File

@ -82,11 +82,11 @@ struct ToStartOfWeekImpl
{
return time_zone.toFirstDayNumOfWeek(DayNum(d), week_mode);
}
static inline Int64 execute_compat(Int64 t, UInt8 week_mode, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, UInt8 week_mode, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t), week_mode);
}
static inline Int32 execute_compat(Int32 d, UInt8 week_mode, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, UInt8 week_mode, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfWeek(ExtendedDayNum(d), week_mode);
}
@ -123,7 +123,7 @@ struct ToWeekImpl
using FactorTransform = ToStartOfYearImpl;
};
template <typename FromType, typename ToType, typename Transform, bool is_compat = false>
template <typename FromType, typename ToType, typename Transform, bool is_extended_result = false>
struct WeekTransformer
{
explicit WeekTransformer(Transform transform_)
@ -138,8 +138,8 @@ struct WeekTransformer
vec_to.resize(size);
for (size_t i = 0; i < size; ++i)
if constexpr (is_compat)
vec_to[i] = transform.execute_compat(vec_from[i], week_mode, time_zone);
if constexpr (is_extended_result)
vec_to[i] = transform.execute_extended_result(vec_from[i], week_mode, time_zone);
else
vec_to[i] = transform.execute(vec_from[i], week_mode, time_zone);
}
@ -149,13 +149,13 @@ private:
};
template <typename FromDataType, typename ToDataType, bool is_compat = false>
template <typename FromDataType, typename ToDataType, bool is_extended_result = false>
struct CustomWeekTransformImpl
{
template <typename Transform>
static ColumnPtr execute(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t /*input_rows_count*/, Transform transform = {})
{
const auto op = WeekTransformer<typename FromDataType::FieldType, typename ToDataType::FieldType, Transform, is_compat>{std::move(transform)};
const auto op = WeekTransformer<typename FromDataType::FieldType, typename ToDataType::FieldType, Transform, is_extended_result>{std::move(transform)};
UInt8 week_mode = DEFAULT_WEEK_MODE;
if (arguments.size() > 1)

View File

@ -161,12 +161,12 @@ struct ToMondayImpl
{
return time_zone.toFirstDayNumOfWeek(DayNum(d));
}
static inline Int64 execute_compat(Int64 t, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, const DateLUTImpl & time_zone)
{
//return time_zone.toFirstDayNumOfWeek(time_zone.toDayNum(t));
return time_zone.toFirstDayNumOfWeek(t);
}
static inline Int32 execute_compat(Int32 d, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfWeek(ExtendedDayNum(d));
}
@ -193,11 +193,11 @@ struct ToStartOfMonthImpl
{
return time_zone.toFirstDayNumOfMonth(DayNum(d));
}
static inline Int64 execute_compat(Int64 t, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfMonth(time_zone.toDayNum(t));
}
static inline Int32 execute_compat(Int32 d, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfMonth(ExtendedDayNum(d));
}
@ -234,11 +234,11 @@ struct ToLastDayOfMonthImpl
/// 0xFFF9 is Int value for 2149-05-31 -- the last day where we can actually find LastDayOfMonth. This will also be the return value.
return time_zone.toLastDayNumOfMonth(DayNum(std::min(d, UInt16(0xFFF9))));
}
static inline Int64 execute_compat(Int64 t, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, const DateLUTImpl & time_zone)
{
return time_zone.toLastDayNumOfMonth(time_zone.toDayNum(t));
}
static inline Int32 execute_compat(Int32 d, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toLastDayNumOfMonth(ExtendedDayNum(d));
}
@ -265,11 +265,11 @@ struct ToStartOfQuarterImpl
{
return time_zone.toFirstDayNumOfQuarter(DayNum(d));
}
static inline Int64 execute_compat(Int64 t, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfQuarter(time_zone.toDayNum(t));
}
static inline Int32 execute_compat(Int32 d, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfQuarter(ExtendedDayNum(d));
}
@ -296,11 +296,11 @@ struct ToStartOfYearImpl
{
return time_zone.toFirstDayNumOfYear(DayNum(d));
}
static inline Int64 execute_compat(Int64 t, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfYear(time_zone.toDayNum(t));
}
static inline Int32 execute_compat(Int32 d, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfYear(ExtendedDayNum(d));
}
@ -945,11 +945,11 @@ struct ToStartOfISOYearImpl
{
return time_zone.toFirstDayNumOfISOYear(DayNum(d));
}
static inline Int64 execute_compat(Int64 t, const DateLUTImpl & time_zone)
static inline Int64 execute_extended_result(Int64 t, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfISOYear(time_zone.toDayNum(t));
}
static inline Int32 execute_compat(Int32 d, const DateLUTImpl & time_zone)
static inline Int32 execute_extended_result(Int32 d, const DateLUTImpl & time_zone)
{
return time_zone.toFirstDayNumOfISOYear(ExtendedDayNum(d));
}
@ -1247,7 +1247,7 @@ struct ToYYYYMMDDhhmmssImpl
};
template <typename FromType, typename ToType, typename Transform, bool is_compat = false>
template <typename FromType, typename ToType, typename Transform, bool is_extended_result = false>
struct Transformer
{
template <typename FromTypeVector, typename ToTypeVector>
@ -1257,21 +1257,21 @@ struct Transformer
vec_to.resize(size);
for (size_t i = 0; i < size; ++i)
if constexpr (is_compat)
vec_to[i] = transform.execute_compat(vec_from[i], time_zone);
if constexpr (is_extended_result)
vec_to[i] = transform.execute_extended_result(vec_from[i], time_zone);
else
vec_to[i] = transform.execute(vec_from[i], time_zone);
}
};
template <typename FromDataType, typename ToDataType, typename Transform, bool is_compat = false>
template <typename FromDataType, typename ToDataType, typename Transform, bool is_extended_result = false>
struct DateTimeTransformImpl
{
static ColumnPtr execute(
const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t /*input_rows_count*/, const Transform & transform = {})
{
using Op = Transformer<typename FromDataType::FieldType, typename ToDataType::FieldType, Transform, is_compat>;
using Op = Transformer<typename FromDataType::FieldType, typename ToDataType::FieldType, Transform, is_extended_result>;
const ColumnPtr source_col = arguments[0].column;
if (const auto * sources = checkAndGetColumn<typename FromDataType::ColumnType>(source_col.get()))

View File

@ -13,7 +13,7 @@ template <typename Transform>
class FunctionCustomWeekToDateOrDate32 : public IFunctionCustomWeek<Transform>, WithContext
{
public:
bool enable_date32_results = false;
bool enable_extended_results_for_datetime_functions = false;
static FunctionPtr create(ContextPtr context_)
{
@ -22,7 +22,7 @@ public:
explicit FunctionCustomWeekToDateOrDate32(ContextPtr context_) : WithContext(context_)
{
enable_date32_results = context_->getSettingsRef().enable_date32_results;
enable_extended_results_for_datetime_functions = context_->getSettingsRef().enable_extended_results_for_datetime_functions;
}
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
@ -31,7 +31,7 @@ public:
const IDataType * from_type = arguments[0].type.get();
WhichDataType which(from_type);
if ((which.isDate32() || which.isDateTime64()) && enable_date32_results)
if ((which.isDate32() || which.isDateTime64()) && enable_extended_results_for_datetime_functions)
return std::make_shared<DataTypeDate32>();
else
return std::make_shared<DataTypeDate>();
@ -46,8 +46,8 @@ public:
return CustomWeekTransformImpl<DataTypeDate, DataTypeDate>::execute(
arguments, result_type, input_rows_count, Transform{});
else if (which.isDate32())
if (enable_date32_results)
return CustomWeekTransformImpl<DataTypeDate32, DataTypeDate32, /*is_compat*/ true>::execute(
if (enable_extended_results_for_datetime_functions)
return CustomWeekTransformImpl<DataTypeDate32, DataTypeDate32, /*is_extended_result*/ true>::execute(
arguments, result_type, input_rows_count, Transform{});
else
return CustomWeekTransformImpl<DataTypeDate32, DataTypeDate>::execute(
@ -57,8 +57,8 @@ public:
arguments, result_type, input_rows_count, Transform{});
else if (which.isDateTime64())
{
if (enable_date32_results)
return CustomWeekTransformImpl<DataTypeDateTime64, DataTypeDate32, /*is_compat*/ true>::execute(
if (enable_extended_results_for_datetime_functions)
return CustomWeekTransformImpl<DataTypeDateTime64, DataTypeDate32, /*is_extended_result*/ true>::execute(
arguments, result_type, input_rows_count,
TransformDateTime64<Transform>{assert_cast<const DataTypeDateTime64 *>(from_type)->getScale()});
else

View File

@ -13,14 +13,14 @@ template <typename Transform>
class FunctionDateOrDateTimeToDateOrDate32 : public IFunctionDateOrDateTime<Transform>, WithContext
{
public:
const bool enable_date32_results = false;
const bool enable_extended_results_for_datetime_functions = false;
static FunctionPtr create(ContextPtr context_)
{
return std::make_shared<FunctionDateOrDateTimeToDateOrDate32>(context_);
}
explicit FunctionDateOrDateTimeToDateOrDate32(ContextPtr context_) : WithContext(context_), enable_date32_results(context_->getSettingsRef().enable_date32_results) { }
explicit FunctionDateOrDateTimeToDateOrDate32(ContextPtr context_) : WithContext(context_), enable_extended_results_for_datetime_functions(context_->getSettingsRef().enable_extended_results_for_datetime_functions) { }
DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
{
@ -37,12 +37,12 @@ public:
throw Exception(
"Function " + this->getName() + " supports a 2nd argument (optional) that must be non-empty and be a valid time zone",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
if (which.isDateTime64() && enable_date32_results)
if (which.isDateTime64() && enable_extended_results_for_datetime_functions)
return std::make_shared<DataTypeDate32>();
else
return std::make_shared<DataTypeDate>();
}
if (which.isDate32() && enable_date32_results)
if (which.isDate32() && enable_extended_results_for_datetime_functions)
return std::make_shared<DataTypeDate32>();
else
return std::make_shared<DataTypeDate>();
@ -56,8 +56,8 @@ public:
if (which.isDate())
return DateTimeTransformImpl<DataTypeDate, DataTypeDate, Transform>::execute(arguments, result_type, input_rows_count);
else if (which.isDate32())
if (enable_date32_results)
return DateTimeTransformImpl<DataTypeDate32, DataTypeDate32, Transform, /*is_compat*/ true>::execute(arguments, result_type, input_rows_count);
if (enable_extended_results_for_datetime_functions)
return DateTimeTransformImpl<DataTypeDate32, DataTypeDate32, Transform, /*is_extended_result*/ true>::execute(arguments, result_type, input_rows_count);
else
return DateTimeTransformImpl<DataTypeDate32, DataTypeDate, Transform>::execute(arguments, result_type, input_rows_count);
else if (which.isDateTime())
@ -67,8 +67,8 @@ public:
const auto scale = static_cast<const DataTypeDateTime64 *>(from_type)->getScale();
const TransformDateTime64<Transform> transformer(scale);
if (enable_date32_results)
return DateTimeTransformImpl<DataTypeDateTime64, DataTypeDate32, decltype(transformer), /*is_compat*/ true>::execute(arguments, result_type, input_rows_count, transformer);
if (enable_extended_results_for_datetime_functions)
return DateTimeTransformImpl<DataTypeDateTime64, DataTypeDate32, decltype(transformer), /*is_extended_result*/ true>::execute(arguments, result_type, input_rows_count, transformer);
else
return DateTimeTransformImpl<DataTypeDateTime64, DataTypeDate, decltype(transformer)>::execute(arguments, result_type, input_rows_count, transformer);
}

View File

@ -89,20 +89,20 @@ public:
template <typename ... Args>
inline auto NO_SANITIZE_UNDEFINED execute_compat(const DateTime64 & t, Args && ... args) const
inline auto NO_SANITIZE_UNDEFINED execute_extended_result(const DateTime64 & t, Args && ... args) const
{
/// Type conversion from float to integer may be required.
/// We are Ok with implementation specific result for out of range and denormals conversion.
if constexpr (TransformHasExecuteOverload_v<DateTime64, decltype(scale_multiplier), Args...>)
{
return wrapped_transform.execute_compat(t, scale_multiplier, std::forward<Args>(args)...);
return wrapped_transform.execute_extended_result(t, scale_multiplier, std::forward<Args>(args)...);
}
else if constexpr (TransformHasExecuteOverload_v<DecimalUtils::DecimalComponents<DateTime64>, Args...>)
{
auto components = DecimalUtils::splitWithScaleMultiplier(t, scale_multiplier);
const auto result = wrapped_transform.execute_compat(components, std::forward<Args>(args)...);
const auto result = wrapped_transform.execute_extended_result(components, std::forward<Args>(args)...);
using ResultType = std::decay_t<decltype(result)>;
if constexpr (std::is_same_v<DecimalUtils::DecimalComponents<DateTime64>, ResultType>)
@ -117,14 +117,14 @@ public:
else
{
const auto components = DecimalUtils::splitWithScaleMultiplier(t, scale_multiplier);
return wrapped_transform.execute_compat(static_cast<Int64>(components.whole), std::forward<Args>(args)...);
return wrapped_transform.execute_extended_result(static_cast<Int64>(components.whole), std::forward<Args>(args)...);
}
}
template <typename T, typename ... Args, typename = std::enable_if_t<!std::is_same_v<T, DateTime64>>>
inline auto execute_compat(const T & t, Args && ... args) const
inline auto execute_extended_result(const T & t, Args && ... args) const
{
return wrapped_transform.execute_compat(t, std::forward<Args>(args)...);
return wrapped_transform.execute_extended_result(t, std::forward<Args>(args)...);
}
private:

View File

@ -1,8 +1,8 @@
{% for option_value in ['true', 'false'] -%}
{% for date_fun in ['toStartOfYear', 'toStartOfISOYear', 'toStartOfQuarter', 'toStartOfMonth', 'toStartOfWeek', 'toMonday', 'toLastDayOfMonth'] -%}
SELECT {{ date_fun }}(toDate32('1950-02-02')) SETTINGS enable_date32_results = {{ option_value }};
SELECT toTypeName({{ date_fun }}(toDate32('1950-02-02'))) SETTINGS enable_date32_results = {{ option_value }};
SELECT {{ date_fun }}(toDateTime64('1950-02-02 10:20:30', 3)) SETTINGS enable_date32_results = {{ option_value }};
SELECT toTypeName({{ date_fun }}(toDateTime64('1950-02-02 10:20:30', 3))) SETTINGS enable_date32_results = {{ option_value }};
SELECT {{ date_fun }}(toDate32('1950-02-02')) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
SELECT toTypeName({{ date_fun }}(toDate32('1950-02-02'))) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
SELECT {{ date_fun }}(toDateTime64('1950-02-02 10:20:30', 3)) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
SELECT toTypeName({{ date_fun }}(toDateTime64('1950-02-02 10:20:30', 3))) SETTINGS enable_extended_results_for_datetime_functions = {{ option_value }};
{% endfor -%}
{% endfor -%}