-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL: Introduce HISTOGRAM grouping function #36510
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c1c6d8
SQL: Introduce HISTOGRAM grouping function
costin bc09b38
Address feedback
costin 6603ce9
More feedback
costin b1d5e62
Merge branch 'master' into introduce-histograms
costin 9256ddf
Merge remote-tracking branch 'remotes/upstream/master' into introduce…
costin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ public abstract class DebugSqlSpec extends SqlSpecTestCase { | |
@ParametersFactory(shuffle = false, argumentFormatting = PARAM_FORMATTING) | ||
public static List<Object[]> readScriptSpec() throws Exception { | ||
Parser parser = specParser(); | ||
return readScriptSpec("/debug.sql-spec", parser); | ||
return readScriptSpec("/datetime.sql-spec", parser); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert |
||
} | ||
|
||
public DebugSqlSpec(String fileName, String groupName, String testName, Integer lineNumber, String query) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add the
beta[]
markerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.