From e8b6ac3fad34f0c49ad11423fa493f00db6a346f Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 7 Jul 2019 02:15:14 +0300 Subject: [PATCH] Returned back support for floating point argument in function quantileTiming --- .../AggregateFunctionQuantile.h | 21 ++++++++----------- .../00753_quantile_format.reference | 4 ++++ .../0_stateless/00753_quantile_format.sql | 8 +++---- ..._quantile_timing_parameter_check.reference | 1 + .../00898_quantile_timing_parameter_check.sql | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/dbms/src/AggregateFunctions/AggregateFunctionQuantile.h b/dbms/src/AggregateFunctions/AggregateFunctionQuantile.h index 0748955f9ef..2e9ec914b99 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionQuantile.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionQuantile.h @@ -82,14 +82,6 @@ public: { if (!returns_many && levels.size() > 1) throw Exception("Aggregate function " + getName() + " require one parameter or less", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - - if constexpr (std::is_same_v>) - { - /// QuantileTiming only supports integers (it works only for unsigned integers but signed are also accepted for convenience). - if (!isInteger(argument_type)) - throw Exception("Argument for function " + std::string(Name::name) + " must be integer, but it has type " - + argument_type->getName(), ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); - } } String getName() const override { return Name::name; } @@ -111,16 +103,21 @@ public: void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override { - /// Out of range conversion may occur. This is Ok. + auto value = static_cast(*columns[0]).getData()[row_num]; - const auto & column = static_cast(*columns[0]); + if constexpr (std::is_same_v>) + { + /// QuantileTiming only supports integers. + if (isNaN(value) || value > std::numeric_limits::max() || value < std::numeric_limits::min()) + return; + } if constexpr (has_second_arg) this->data(place).add( - column.getData()[row_num], + value, columns[1]->getUInt(row_num)); else - this->data(place).add(column.getData()[row_num]); + this->data(place).add(value); } void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena *) const override diff --git a/dbms/tests/queries/0_stateless/00753_quantile_format.reference b/dbms/tests/queries/0_stateless/00753_quantile_format.reference index e61cee21c64..04bb0000b3e 100644 --- a/dbms/tests/queries/0_stateless/00753_quantile_format.reference +++ b/dbms/tests/queries/0_stateless/00753_quantile_format.reference @@ -6,6 +6,10 @@ ['2016-06-15 23:00:00'] 2016-06-15 23:00:00 ['2016-06-15 23:00:00'] +30000 +[30000] +30000 +[30000] 2016-06-15 23:01:04 ['2016-06-15 23:01:04'] 2016-06-15 23:01:04 diff --git a/dbms/tests/queries/0_stateless/00753_quantile_format.sql b/dbms/tests/queries/0_stateless/00753_quantile_format.sql index 3a0947015ea..24cf0e4bf90 100644 --- a/dbms/tests/queries/0_stateless/00753_quantile_format.sql +++ b/dbms/tests/queries/0_stateless/00753_quantile_format.sql @@ -15,11 +15,11 @@ SELECT quantilesExact(0.2)(d) FROM datetime; SELECT quantileExactWeighted(0.2)(d, 1) FROM datetime; SELECT quantilesExactWeighted(0.2)(d, 1) FROM datetime; -SELECT quantileTiming(0.2)(d) FROM datetime; -- { serverError 43 } -SELECT quantilesTiming(0.2)(d) FROM datetime; -- { serverError 43 } +SELECT quantileTiming(0.2)(d) FROM datetime; +SELECT quantilesTiming(0.2)(d) FROM datetime; -SELECT quantileTimingWeighted(0.2)(d, 1) FROM datetime; -- { serverError 43 } -SELECT quantilesTimingWeighted(0.2)(d, 1) FROM datetime; -- { serverError 43 } +SELECT quantileTimingWeighted(0.2)(d, 1) FROM datetime; +SELECT quantilesTimingWeighted(0.2)(d, 1) FROM datetime; SELECT quantileTDigest(0.2)(d) FROM datetime; SELECT quantilesTDigest(0.2)(d) FROM datetime; diff --git a/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.reference b/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.reference index 7ed6ff82de6..47586a86a32 100644 --- a/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.reference +++ b/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.reference @@ -1 +1,2 @@ 5 +2 diff --git a/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.sql b/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.sql index 8279804a22c..ce1f3e897d3 100644 --- a/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.sql +++ b/dbms/tests/queries/0_stateless/00898_quantile_timing_parameter_check.sql @@ -1,2 +1,2 @@ SELECT quantileTiming(0.5)(number) FROM numbers(10); -SELECT quantileTiming(0.5)(number / 2) FROM numbers(10); -- { serverError 43 } +SELECT quantileTiming(0.5)(number / 2) FROM numbers(10);