-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL: Introduce HISTOGRAM grouping function (#36510)
Introduce Histogram grouping function for bucketing/grouping data based on a given range. Both date and numeric histograms are supported using the appropriate range declaration (numbers vs intervals). SELECT HISTOGRAM(number, 50) AS h FROM index GROUP BY h SELECT HISTOGRAM(date, INTERVAL 1 YEAR) AS h FROM index GROUP BY h In addition add multiply operator for Intervals Add docs for intervals and histogram Fix #36509 (cherry picked from commit 6ee6bb5)
- Loading branch information
Showing
56 changed files
with
1,428 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[role="xpack"] | ||
[testenv="basic"] | ||
[[sql-functions-grouping]] | ||
=== Grouping Functions | ||
|
||
beta[] | ||
|
||
Functions for creating special __grouping__s (also known as _bucketing_); as such these need to be used | ||
as part of the <<sql-syntax-group-by, grouping>>. | ||
|
||
[[sql-functions-grouping-histogram]] | ||
==== `HISTOGRAM` | ||
|
||
.Synopsis | ||
[source, sql] | ||
---- | ||
HISTOGRAM ( numeric_exp<1>, numeric_interval<2>) | ||
HISTOGRAM ( date_exp<3>, date_time_interval<4>) | ||
---- | ||
|
||
*Input*: | ||
|
||
<1> numeric expression (typically a field) | ||
<2> numeric interval | ||
<3> date/time expression (typically a field) | ||
<4> date/time <<sql-functions-datetime-interval, interval>> | ||
|
||
*Output*: non-empty buckets or groups of the given expression divided according to the given interval | ||
|
||
.Description | ||
|
||
The histogram function takes all matching values and divides them into buckets with fixed size matching the given interval, using (roughly) the following formula: | ||
|
||
[source, sql] | ||
---- | ||
bucket_key = Math.floor(value / interval) * interval | ||
---- | ||
|
||
`Histogram` can be applied on either numeric fields: | ||
|
||
|
||
["source","sql",subs="attributes,callouts,macros"] | ||
---- | ||
include-tagged::{sql-specs}/docs.csv-spec[histogramNumeric] | ||
---- | ||
|
||
or date/time fields: | ||
|
||
["source","sql",subs="attributes,callouts,macros"] | ||
---- | ||
include-tagged::{sql-specs}/docs.csv-spec[histogramDate] | ||
---- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.