Add tests.

This commit is contained in:
zhangxiao871 2021-08-15 19:50:32 +08:00
parent deb2c4569f
commit 72ba479b26
3 changed files with 36 additions and 22 deletions

View File

@ -29,10 +29,9 @@ struct AggregateFunctionSparkbarData
it->second += y;
else
points.emplace(x, y);
if (y < min_y)
min_y = y;
if (y > max_y)
max_y = y;
min_y = std::min(y, min_y);
max_y = std::max(y, max_y);
}
void merge(const AggregateFunctionSparkbarData & other)
@ -49,11 +48,8 @@ struct AggregateFunctionSparkbarData
points.emplace(point.first, point.second);
}
if (other.min_y < min_y)
min_y = other.min_y;
if (other.max_y > max_y)
max_y = other.max_y;
min_y = std::min(other.min_y, min_y);
max_y = std::max(other.max_y, max_y);
}
void serialize(WriteBuffer & buf) const
@ -133,6 +129,8 @@ private:
String render(const AggregateFunctionSparkbarData<X, Y> & data) const
{
String value;
if (data.points.empty())
return value;
X local_min_x = data.points.begin()->first;
X local_max_x = data.points.rbegin()->first;
size_t diff_x = local_max_x - local_min_x;

View File

@ -9,3 +9,10 @@
▁▅▄▃██▅ ▁
▁▄▄▂▅▇█▂ ▂
▁▄▅▂▃▇▆█ ▂
▆█▁▃
▅▁▂█▇
▁▂▇▆█ ▁

View File

@ -1,17 +1,26 @@
drop table if exists spark_bar_test;
DROP TABLE IF EXISTS spark_bar_test;
CREATE TABLE spark_bar_test (`cnt` UInt64,`event_date` Date) ENGINE = MergeTree ORDER BY event_date SETTINGS index_granularity = 8192;
insert into spark_bar_test values(1,'2020-01-01'),(4,'2020-01-02'),(5,'2020-01-03'),(2,'2020-01-04'),(3,'2020-01-05'),(7,'2020-01-06'),(6,'2020-01-07'),(8,'2020-01-08'),(2,'2020-01-11');
INSERT INTO spark_bar_test VALUES(1,'2020-01-01'),(4,'2020-01-02'),(5,'2020-01-03'),(2,'2020-01-04'),(3,'2020-01-05'),(7,'2020-01-06'),(6,'2020-01-07'),(8,'2020-01-08'),(2,'2020-01-11');
select sparkbar(1)(event_date,cnt) from spark_bar_test;
select sparkbar(2)(event_date,cnt) from spark_bar_test;
select sparkbar(3)(event_date,cnt) from spark_bar_test;
select sparkbar(4)(event_date,cnt) from spark_bar_test;
select sparkbar(5)(event_date,cnt) from spark_bar_test;
select sparkbar(6)(event_date,cnt) from spark_bar_test;
select sparkbar(7)(event_date,cnt) from spark_bar_test;
select sparkbar(8)(event_date,cnt) from spark_bar_test;
select sparkbar(9)(event_date,cnt) from spark_bar_test;
select sparkbar(10)(event_date,cnt) from spark_bar_test;
select sparkbar(11)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(1)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(2)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(3)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(4)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(5)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(6)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(7)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(8)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(9)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(10)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,2,5)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,3,7)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,4,11)(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,toDate('2020-01-02'),toDate('2020-01-02'))(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,toDate('2020-01-02'),toDate('2020-01-05'))(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,toDate('2020-01-03'),toDate('2020-01-07'))(event_date,cnt) from spark_bar_test;
SELECT sparkbar(11,toDate('2020-01-04'),toDate('2020-01-11'))(event_date,cnt) from spark_bar_test;