diff --git a/dbms/src/AggregateFunctions/AggregateFunctionTSGroupSum.cpp b/dbms/src/AggregateFunctions/AggregateFunctionTSGroupSum.cpp deleted file mode 100644 index 765e12b86e5..00000000000 --- a/dbms/src/AggregateFunctions/AggregateFunctionTSGroupSum.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "AggregateFunctionTSGroupSum.h" -#include "AggregateFunctionFactory.h" -#include "FactoryHelpers.h" -#include "Helpers.h" - - -namespace DB -{ -namespace -{ - template - AggregateFunctionPtr createAggregateFunctionTSgroupSum(const std::string & name, const DataTypes & arguments, const Array & params) - { - assertNoParameters(name, params); - - if (arguments.size() < 3) - throw Exception("Not enough event arguments for aggregate function " + name, ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); - - return std::make_shared>(arguments); - } - -} - -void registerAggregateFunctionTSgroupSum(AggregateFunctionFactory & factory) -{ - factory.registerFunction("TSgroupSum", createAggregateFunctionTSgroupSum, AggregateFunctionFactory::CaseInsensitive); - factory.registerFunction("TSgroupRateSum", createAggregateFunctionTSgroupSum, AggregateFunctionFactory::CaseInsensitive); -} - -} diff --git a/dbms/src/AggregateFunctions/AggregateFunctionTimeSeriesGroupSum.cpp b/dbms/src/AggregateFunctions/AggregateFunctionTimeSeriesGroupSum.cpp new file mode 100644 index 00000000000..8f3f64d9e93 --- /dev/null +++ b/dbms/src/AggregateFunctions/AggregateFunctionTimeSeriesGroupSum.cpp @@ -0,0 +1,30 @@ +#include "AggregateFunctionTimeSeriesGroupSum.h" +#include "AggregateFunctionFactory.h" +#include "FactoryHelpers.h" +#include "Helpers.h" + + +namespace DB +{ +namespace +{ + template + AggregateFunctionPtr createAggregateFunctionTimeSeriesGroupSum(const std::string & name, const DataTypes & arguments, const Array & params) + { + assertNoParameters(name, params); + + if (arguments.size() < 3) + throw Exception("Not enough event arguments for aggregate function " + name, ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); + + return std::make_shared>(arguments); + } + +} + +void registerAggregateFunctionTimeSeriesGroupSum(AggregateFunctionFactory & factory) +{ + factory.registerFunction("timeSeriesGroupSum", createAggregateFunctionTimeSeriesGroupSum, AggregateFunctionFactory::CaseInsensitive); + factory.registerFunction("timeSeriesGroupRateSum", createAggregateFunctionTimeSeriesGroupSum, AggregateFunctionFactory::CaseInsensitive); +} + +} diff --git a/dbms/src/AggregateFunctions/AggregateFunctionTSGroupSum.h b/dbms/src/AggregateFunctions/AggregateFunctionTimeSeriesGroupSum.h similarity index 92% rename from dbms/src/AggregateFunctions/AggregateFunctionTSGroupSum.h rename to dbms/src/AggregateFunctions/AggregateFunctionTimeSeriesGroupSum.h index f82e00da8ef..c74ad8c0bdb 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionTSGroupSum.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionTimeSeriesGroupSum.h @@ -28,7 +28,7 @@ namespace ErrorCodes extern const int TOO_MANY_ARGUMENTS_FOR_FUNCTION; } template -struct AggregateFunctionTSgroupSumData +struct AggregateFunctionTimeSeriesGroupSumData { using DataPoint = std::pair; struct Points @@ -90,7 +90,7 @@ struct AggregateFunctionTSgroupSumData it_ss->second.add(t, v); } if (result.size() > 0 && t < result.back().first) - throw Exception{"TSgroupSum or TSgroupRateSum must order by timestamp asc!!!", ErrorCodes::LOGICAL_ERROR}; + throw Exception{"timeSeriesGroupSum or timeSeriesGroupRateSum must order by timestamp asc!!!", ErrorCodes::LOGICAL_ERROR}; if (result.size() > 0 && t == result.back().first) { //do not add new point @@ -119,7 +119,7 @@ struct AggregateFunctionTSgroupSumData } } - void merge(const AggregateFunctionTSgroupSumData & other) + void merge(const AggregateFunctionTimeSeriesGroupSumData & other) { //if ts has overlap, then aggregate two series by interpolation; AggSeries tmp; @@ -199,15 +199,15 @@ struct AggregateFunctionTSgroupSumData } }; template -class AggregateFunctionTSgroupSum final - : public IAggregateFunctionDataHelper, AggregateFunctionTSgroupSum> +class AggregateFunctionTimeSeriesGroupSum final + : public IAggregateFunctionDataHelper, AggregateFunctionTimeSeriesGroupSum> { private: public: - String getName() const override { return rate ? "TSgroupRateSum" : "TSgroupSum"; } + String getName() const override { return rate ? "timeSeriesGroupRateSum" : "timeSeriesGroupSum"; } - AggregateFunctionTSgroupSum(const DataTypes & arguments) - : IAggregateFunctionDataHelper, AggregateFunctionTSgroupSum>(arguments, {}) + AggregateFunctionTimeSeriesGroupSum(const DataTypes & arguments) + : IAggregateFunctionDataHelper, AggregateFunctionTimeSeriesGroupSum>(arguments, {}) { if (!WhichDataType(arguments[0].get()).isUInt64()) throw Exception{"Illegal type " + arguments[0].get()->getName() + " of argument 1 of aggregate function " + getName() diff --git a/dbms/src/AggregateFunctions/registerAggregateFunctions.cpp b/dbms/src/AggregateFunctions/registerAggregateFunctions.cpp index 3148a4e726b..44c61425ea4 100644 --- a/dbms/src/AggregateFunctions/registerAggregateFunctions.cpp +++ b/dbms/src/AggregateFunctions/registerAggregateFunctions.cpp @@ -41,7 +41,7 @@ void registerAggregateFunctionCombinatorNull(AggregateFunctionCombinatorFactory void registerAggregateFunctionHistogram(AggregateFunctionFactory & factory); void registerAggregateFunctionRetention(AggregateFunctionFactory & factory); -void registerAggregateFunctionTSgroupSum(AggregateFunctionFactory & factory); +void registerAggregateFunctionTimeSeriesGroupSum(AggregateFunctionFactory & factory); void registerAggregateFunctions() { { @@ -70,7 +70,7 @@ void registerAggregateFunctions() registerAggregateFunctionsMaxIntersections(factory); registerAggregateFunctionHistogram(factory); registerAggregateFunctionRetention(factory); - registerAggregateFunctionTSgroupSum(factory); + registerAggregateFunctionTimeSeriesGroupSum(factory); registerAggregateFunctionMLMethod(factory); registerAggregateFunctionEntropy(factory); registerAggregateFunctionLeastSqr(factory); diff --git a/dbms/tests/queries/0_stateless/00910_aggregation_tsgroupsum.reference b/dbms/tests/queries/0_stateless/00910_aggregation_timeseriesgroupsum.reference similarity index 100% rename from dbms/tests/queries/0_stateless/00910_aggregation_tsgroupsum.reference rename to dbms/tests/queries/0_stateless/00910_aggregation_timeseriesgroupsum.reference diff --git a/dbms/tests/queries/0_stateless/00910_aggregation_tsgroupsum.sql b/dbms/tests/queries/0_stateless/00910_aggregation_timeseriesgroupsum.sql similarity index 62% rename from dbms/tests/queries/0_stateless/00910_aggregation_tsgroupsum.sql rename to dbms/tests/queries/0_stateless/00910_aggregation_timeseriesgroupsum.sql index b73536dede8..3a1a334469c 100644 --- a/dbms/tests/queries/0_stateless/00910_aggregation_tsgroupsum.sql +++ b/dbms/tests/queries/0_stateless/00910_aggregation_timeseriesgroupsum.sql @@ -4,7 +4,7 @@ create table tsgroupsum_test (uid UInt64, ts Int64, value Float64) engine=Memory insert into tsgroupsum_test values (1,2,0.2),(1,7,0.7),(1,12,1.2),(1,17,1.7),(1,25,2.5); insert into tsgroupsum_test values (2,3,0.6),(2,8,1.6),(2,12,2.4),(2,18,3.6),(2,24,4.8); -select TSgroupSum(uid, ts, value) from (select * from tsgroupsum_test order by ts asc); -select TSgroupRateSum(uid, ts, value) from (select * from tsgroupsum_test order by ts asc); +select timeSeriesGroupSum(uid, ts, value) from (select * from tsgroupsum_test order by ts asc); +select timeSeriesGroupRateSum(uid, ts, value) from (select * from tsgroupsum_test order by ts asc); drop table tsgroupsum_test; diff --git a/docs/en/query_language/agg_functions/reference.md b/docs/en/query_language/agg_functions/reference.md index 0536db5a4fb..0d63c8425f7 100644 --- a/docs/en/query_language/agg_functions/reference.md +++ b/docs/en/query_language/agg_functions/reference.md @@ -301,8 +301,8 @@ GROUP BY timeslot └─────────────────────┴──────────────────────────────────────────────┘ ``` -## TSgroupSum(uid, timestamp, value) {#agg_function-tsgroupsum} -TSgroupSum can aggregate different time series that sample timestamp not alignment. +## timeSeriesGroupSum(uid, timestamp, value) {#agg_function-timeseriesgroupsum} +timeSeriesGroupSum can aggregate different time series that sample timestamp not alignment. It will use linear interpolation between two sample timestamp and then sum time-series together. `uid` is the time series unique id, UInt64. @@ -336,7 +336,7 @@ INSERT INTO time_series VALUES (1,2,0.2),(1,7,0.7),(1,12,1.2),(1,17,1.7),(1,25,2.5), (2,3,0.6),(2,8,1.6),(2,12,2.4),(2,18,3.6),(2,24,4.8); -SELECT TSgroupSum(uid, timestamp, value) +SELECT timeSeriesGroupSum(uid, timestamp, value) FROM ( SELECT * FROM time_series order by timestamp ASC ); @@ -346,8 +346,8 @@ And the result will be: [(2,0.2),(3,0.9),(7,2.1),(8,2.4),(12,3.6),(17,5.1),(18,5.4),(24,7.2),(25,2.5)] ``` -## TSgroupRateSum(uid, ts, val) {#agg_function-tsgroupratesum} -Similarly TSgroupRateSum, TSgroupRateSum will Calculate the rate of time-series and then sum rates together. +## timeSeriesGroupRateSum(uid, ts, val) {#agg_function-timeseriesgroupratesum} +Similarly timeSeriesGroupRateSum, timeSeriesGroupRateSum will Calculate the rate of time-series and then sum rates together. Also, timestamp should be in ascend order before use this function. Use this function, the result above case will be: