mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
2.9 KiB
2.9 KiB
slug | sidebar_position | sidebar_label |
---|---|---|
/en/sql-reference/aggregate-functions/reference/largestTriangleThreeBuckets | 312 | largestTriangleThreeBuckets |
largestTriangleThreeBuckets
Applies the Largest-Triangle-Three-Buckets algorithm to the input data.
The algorithm is used for downsampling time series data for visualization. It is designed to operate on series sorted by x coordinate.
It works by dividing the sorted series into buckets and then finding the largest triangle in each bucket. The number of buckets is equal to the number of points in the resulting series.
the function will sort data by x
and then apply the downsampling algorithm to the sorted data.
Syntax
largestTriangleThreeBuckets(n)(x, y)
Alias: lttb
.
Arguments
x
— x coordinate. Integer , Float , Decimal , Date, Date32, DateTime, DateTime64.y
— y coordinate. Integer , Float , Decimal , Date, Date32, DateTime, DateTime64.
Parameters
n
— number of points in the resulting series. UInt64.
Returned values
Array of Tuple with two elements:
Example
Input table:
┌─────x───────┬───────y──────┐
│ 1.000000000 │ 10.000000000 │
│ 2.000000000 │ 20.000000000 │
│ 3.000000000 │ 15.000000000 │
│ 8.000000000 │ 60.000000000 │
│ 9.000000000 │ 55.000000000 │
│ 10.00000000 │ 70.000000000 │
│ 4.000000000 │ 30.000000000 │
│ 5.000000000 │ 40.000000000 │
│ 6.000000000 │ 35.000000000 │
│ 7.000000000 │ 50.000000000 │
└─────────────┴──────────────┘
Query:
SELECT largestTriangleThreeBuckets(4)(x, y) FROM largestTriangleThreeBuckets_test;
Result:
┌────────largestTriangleThreeBuckets(4)(x, y)───────────┐
│ [(1,10),(3,15),(5,40),(10,70)] │
└───────────────────────────────────────────────────────┘