mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-05 15:21:43 +00:00
Rename aggregate functions TSgroup* to timeSeriesGroup*
This commit is contained in:
parent
3340ae66ba
commit
978ce3dcf0
@ -1,30 +0,0 @@
|
||||
#include "AggregateFunctionTSGroupSum.h"
|
||||
#include "AggregateFunctionFactory.h"
|
||||
#include "FactoryHelpers.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template <bool rate>
|
||||
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<AggregateFunctionTSgroupSum<rate>>(arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerAggregateFunctionTSgroupSum(AggregateFunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction("TSgroupSum", createAggregateFunctionTSgroupSum<false>, AggregateFunctionFactory::CaseInsensitive);
|
||||
factory.registerFunction("TSgroupRateSum", createAggregateFunctionTSgroupSum<true>, AggregateFunctionFactory::CaseInsensitive);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#include "AggregateFunctionTimeSeriesGroupSum.h"
|
||||
#include "AggregateFunctionFactory.h"
|
||||
#include "FactoryHelpers.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template <bool rate>
|
||||
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<AggregateFunctionTimeSeriesGroupSum<rate>>(arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerAggregateFunctionTimeSeriesGroupSum(AggregateFunctionFactory & factory)
|
||||
{
|
||||
factory.registerFunction("timeSeriesGroupSum", createAggregateFunctionTimeSeriesGroupSum<false>, AggregateFunctionFactory::CaseInsensitive);
|
||||
factory.registerFunction("timeSeriesGroupRateSum", createAggregateFunctionTimeSeriesGroupSum<true>, AggregateFunctionFactory::CaseInsensitive);
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ namespace ErrorCodes
|
||||
extern const int TOO_MANY_ARGUMENTS_FOR_FUNCTION;
|
||||
}
|
||||
template <bool rate>
|
||||
struct AggregateFunctionTSgroupSumData
|
||||
struct AggregateFunctionTimeSeriesGroupSumData
|
||||
{
|
||||
using DataPoint = std::pair<Int64, Float64>;
|
||||
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 <bool rate>
|
||||
class AggregateFunctionTSgroupSum final
|
||||
: public IAggregateFunctionDataHelper<AggregateFunctionTSgroupSumData<rate>, AggregateFunctionTSgroupSum<rate>>
|
||||
class AggregateFunctionTimeSeriesGroupSum final
|
||||
: public IAggregateFunctionDataHelper<AggregateFunctionTimeSeriesGroupSumData<rate>, AggregateFunctionTimeSeriesGroupSum<rate>>
|
||||
{
|
||||
private:
|
||||
public:
|
||||
String getName() const override { return rate ? "TSgroupRateSum" : "TSgroupSum"; }
|
||||
String getName() const override { return rate ? "timeSeriesGroupRateSum" : "timeSeriesGroupSum"; }
|
||||
|
||||
AggregateFunctionTSgroupSum(const DataTypes & arguments)
|
||||
: IAggregateFunctionDataHelper<AggregateFunctionTSgroupSumData<rate>, AggregateFunctionTSgroupSum<rate>>(arguments, {})
|
||||
AggregateFunctionTimeSeriesGroupSum(const DataTypes & arguments)
|
||||
: IAggregateFunctionDataHelper<AggregateFunctionTimeSeriesGroupSumData<rate>, AggregateFunctionTimeSeriesGroupSum<rate>>(arguments, {})
|
||||
{
|
||||
if (!WhichDataType(arguments[0].get()).isUInt64())
|
||||
throw Exception{"Illegal type " + arguments[0].get()->getName() + " of argument 1 of aggregate function " + getName()
|
@ -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);
|
||||
|
@ -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;
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user