mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Merge pull request #58335 from lingtaolf/feature/sparkBar_alias_to_sparkbar
sparkBar as an alias to sparkbar
This commit is contained in:
commit
09181b6c37
@ -1,62 +1,64 @@
|
|||||||
---
|
---
|
||||||
slug: /en/sql-reference/aggregate-functions/reference/sparkbar
|
slug: /en/sql-reference/aggregate-functions/reference/sparkbar
|
||||||
sidebar_position: 311
|
sidebar_position: 311
|
||||||
sidebar_label: sparkbar
|
sidebar_label: sparkbar
|
||||||
---
|
---
|
||||||
|
|
||||||
# sparkbar
|
# sparkbar
|
||||||
|
|
||||||
The function plots a frequency histogram for values `x` and the repetition rate `y` of these values over the interval `[min_x, max_x]`.
|
The function plots a frequency histogram for values `x` and the repetition rate `y` of these values over the interval `[min_x, max_x]`.
|
||||||
Repetitions for all `x` falling into the same bucket are averaged, so data should be pre-aggregated.
|
Repetitions for all `x` falling into the same bucket are averaged, so data should be pre-aggregated.
|
||||||
Negative repetitions are ignored.
|
Negative repetitions are ignored.
|
||||||
|
|
||||||
If no interval is specified, then the minimum `x` is used as the interval start, and the maximum `x` — as the interval end.
|
If no interval is specified, then the minimum `x` is used as the interval start, and the maximum `x` — as the interval end.
|
||||||
Otherwise, values outside the interval are ignored.
|
Otherwise, values outside the interval are ignored.
|
||||||
|
|
||||||
**Syntax**
|
**Syntax**
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
sparkbar(buckets[, min_x, max_x])(x, y)
|
sparkbar(buckets[, min_x, max_x])(x, y)
|
||||||
```
|
```
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `buckets` — The number of segments. Type: [Integer](../../../sql-reference/data-types/int-uint.md).
|
- `buckets` — The number of segments. Type: [Integer](../../../sql-reference/data-types/int-uint.md).
|
||||||
- `min_x` — The interval start. Optional parameter.
|
- `min_x` — The interval start. Optional parameter.
|
||||||
- `max_x` — The interval end. Optional parameter.
|
- `max_x` — The interval end. Optional parameter.
|
||||||
|
|
||||||
**Arguments**
|
**Arguments**
|
||||||
|
|
||||||
- `x` — The field with values.
|
- `x` — The field with values.
|
||||||
- `y` — The field with the frequency of values.
|
- `y` — The field with the frequency of values.
|
||||||
|
|
||||||
**Returned value**
|
**Returned value**
|
||||||
|
|
||||||
- The frequency histogram.
|
- The frequency histogram.
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
Query:
|
Query:
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
CREATE TABLE spark_bar_data (`value` Int64, `event_date` Date) ENGINE = MergeTree ORDER BY event_date;
|
CREATE TABLE spark_bar_data (`value` Int64, `event_date` Date) ENGINE = MergeTree ORDER BY event_date;
|
||||||
|
|
||||||
INSERT INTO spark_bar_data VALUES (1,'2020-01-01'), (3,'2020-01-02'), (4,'2020-01-02'), (-3,'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_data VALUES (1,'2020-01-01'), (3,'2020-01-02'), (4,'2020-01-02'), (-3,'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(9)(event_date,cnt) FROM (SELECT sum(value) as cnt, event_date FROM spark_bar_data GROUP BY event_date);
|
SELECT sparkbar(9)(event_date,cnt) FROM (SELECT sum(value) as cnt, event_date FROM spark_bar_data GROUP BY event_date);
|
||||||
|
|
||||||
SELECT sparkbar(9, toDate('2020-01-01'), toDate('2020-01-10'))(event_date,cnt) FROM (SELECT sum(value) as cnt, event_date FROM spark_bar_data GROUP BY event_date);
|
SELECT sparkbar(9, toDate('2020-01-01'), toDate('2020-01-10'))(event_date,cnt) FROM (SELECT sum(value) as cnt, event_date FROM spark_bar_data GROUP BY event_date);
|
||||||
```
|
```
|
||||||
|
|
||||||
Result:
|
Result:
|
||||||
|
|
||||||
``` text
|
``` text
|
||||||
┌─sparkbar(9)(event_date, cnt)─┐
|
┌─sparkbar(9)(event_date, cnt)─┐
|
||||||
│ ▂▅▂▃▆█ ▂ │
|
│ ▂▅▂▃▆█ ▂ │
|
||||||
└──────────────────────────────┘
|
└──────────────────────────────┘
|
||||||
|
|
||||||
┌─sparkbar(9, toDate('2020-01-01'), toDate('2020-01-10'))(event_date, cnt)─┐
|
┌─sparkbar(9, toDate('2020-01-01'), toDate('2020-01-10'))(event_date, cnt)─┐
|
||||||
│ ▂▅▂▃▇▆█ │
|
│ ▂▅▂▃▇▆█ │
|
||||||
└──────────────────────────────────────────────────────────────────────────┘
|
└──────────────────────────────────────────────────────────────────────────┘
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The alias for this function is sparkBar.
|
||||||
|
|
||||||
|
@ -378,6 +378,7 @@ AggregateFunctionPtr createAggregateFunctionSparkbar(const std::string & name, c
|
|||||||
void registerAggregateFunctionSparkbar(AggregateFunctionFactory & factory)
|
void registerAggregateFunctionSparkbar(AggregateFunctionFactory & factory)
|
||||||
{
|
{
|
||||||
factory.registerFunction("sparkbar", createAggregateFunctionSparkbar);
|
factory.registerFunction("sparkbar", createAggregateFunctionSparkbar);
|
||||||
|
factory.registerAlias("sparkBar", "sparkbar");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
▂▅▂▃▆█ ▂
|
||||||
|
▂▅▂▃▆█ ▂
|
12
tests/queries/0_stateless/02955_sparkBar_alias_sparkbar.sql
Normal file
12
tests/queries/0_stateless/02955_sparkBar_alias_sparkbar.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
SET allow_experimental_analyzer = 1;
|
||||||
|
DROP TABLE IF EXISTS spark_bar_test;
|
||||||
|
|
||||||
|
CREATE TABLE spark_bar_test (`value` Int64, `event_date` Date) ENGINE = MergeTree ORDER BY event_date;
|
||||||
|
|
||||||
|
INSERT INTO spark_bar_test VALUES (1,'2020-01-01'), (3,'2020-01-02'), (4,'2020-01-02'), (-3,'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(9)(event_date,cnt) FROM (SELECT sum(value) as cnt, event_date FROM spark_bar_test GROUP BY event_date);
|
||||||
|
SELECT sparkBar(9)(event_date,cnt) FROM (SELECT sum(value) as cnt, event_date FROM spark_bar_test GROUP BY event_date);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS spark_bar_test;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user