-
Notifications
You must be signed in to change notification settings - Fork 25.9k
ESQL: INLINESTATS #109583
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
Merged
Merged
ESQL: INLINESTATS #109583
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
e2d9da7
ESQL: INLINESTATS
nik9000 14017d6
Explain
nik9000 355905a
More nocommit
nik9000 a634f90
More nocommit
nik9000 8f04e1b
Spotless
nik9000 3a3939b
Merge branch 'main' into inlinestats
nik9000 5483426
Works again
nik9000 7695f67
Closer
nik9000 64f858b
Merge branch 'main' into inlinestats
nik9000 141a63f
More test
nik9000 d0dc736
Share
nik9000 6947e1c
Merge branch 'main' into inlinestats
nik9000 cc44421
More
nik9000 8466a4e
ungrouped
nik9000 cc20b73
WIt P
nik9000 2f9b8af
Merge branch 'main' into inlinestats
nik9000 c4f1d87
Remove
nik9000 1408824
Remove unused
nik9000 2a38bc8
Merge branch 'main' into inlinestats
nik9000 b786c1c
More test
nik9000 547e5a5
Merge
nik9000 0eb2958
More nocommit
nik9000 32a03b2
explain
nik9000 966c860
Merge branch 'main' into inlinestats
nik9000 83252cf
WIP
nik9000 40d3fe9
Passes now?
nik9000 50fc6e2
one more exampl
nik9000 d33a445
Merge branch 'main' into inlinestats
nik9000 a868e7e
Javadoc
nik9000 0bbdef4
MOAR JAVADOC
nik9000 e19c769
Update docs/changelog/109583.yaml
nik9000 5d019f4
Changelog
nik9000 434bd9b
WIP
nik9000 0d5d0da
Merge branch 'main' into inlinestats
nik9000 e7eb532
Ready?
nik9000 908dfc9
Update docs
nik9000 2386fa8
Raname to line up with other stuff
nik9000 887b9ce
More
nik9000 2e028ce
Merge branch 'main' into inlinestats
nik9000 1dfe527
Merge branch 'main' into inlinestats
nik9000 ab350c4
Apply suggestions from code review
nik9000 2d90569
Merge remote-tracking branch 'nik9000/inlinestats' into inlinestats
nik9000 c937834
Update docs
nik9000 0a9332c
Updates
nik9000 c30230c
More explain and a couple renames
nik9000 9d12a29
Format
nik9000 6f690b7
Merge branch 'main' into inlinestats
nik9000 18d30f0
Some progress
nik9000 9ff0024
percentile
nik9000 c142d61
Better way?
nik9000 76998b7
Merge branch 'main' into inlinestats
nik9000 40b13df
techpreview
nik9000 48253a4
Merge branch 'main' into inlinestats
nik9000 674d93d
WIP
nik9000 4489b27
Update
nik9000 8074a95
Merge branch 'main' into inlinestats
nik9000 10b1fcd
Link
nik9000 fdb43d8
Check
nik9000 cbb1e60
Feature flag it
nik9000 8fbe301
Merge branch 'main' into inlinestats
nik9000 09d226a
WI{
nik9000 0e454f7
Merge branch 'main' into inlinestats
nik9000 a6ec9be
more skips
nik9000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
| pr: 109583 | ||
| summary: "ESQL: INLINESTATS" | ||
| area: ES|QL | ||
| type: feature | ||
| issues: | ||
| - 107589 | ||
| highlight: | ||
| title: "ESQL: INLINESTATS" | ||
| body: |- | ||
| This adds the `INLINESTATS` command to ESQL which performs a STATS and | ||
| then enriches the results into the output stream. So, this query: | ||
|
|
||
| [source,esql] | ||
| ---- | ||
| FROM test | ||
| | INLINESTATS m=MAX(a * b) BY b | ||
| | WHERE m == a * b | ||
| | SORT a DESC, b DESC | ||
| | LIMIT 3 | ||
| ---- | ||
|
|
||
| Produces output like: | ||
|
|
||
| | a | b | m | | ||
| | --- | --- | ----- | | ||
| | 99 | 999 | 98901 | | ||
| | 99 | 998 | 98802 | | ||
| | 99 | 997 | 98703 | | ||
| notable: true |
This file contains hidden or 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
102 changes: 102 additions & 0 deletions
102
docs/reference/esql/processing-commands/inlinestats.asciidoc
This file contains hidden or 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,102 @@ | ||
| [discrete] | ||
| [[esql-inlinestats-by]] | ||
| === `INLINESTATS ... BY` | ||
|
|
||
| experimental::["INLINESTATS is highly experimental and only available in SNAPSHOT versions."] | ||
|
|
||
| The `INLINESTATS` command calculates an aggregate result and adds new columns | ||
| with the result to the stream of input data. | ||
|
|
||
| **Syntax** | ||
|
|
||
| [source,esql] | ||
| ---- | ||
| INLINESTATS [column1 =] expression1[, ..., [columnN =] expressionN] | ||
| [BY grouping_expression1[, ..., grouping_expressionN]] | ||
| ---- | ||
|
|
||
| *Parameters* | ||
|
|
||
| `columnX`:: | ||
| The name by which the aggregated value is returned. If omitted, the name is | ||
| equal to the corresponding expression (`expressionX`). If multiple columns | ||
| have the same name, all but the rightmost column with this name will be ignored. | ||
|
|
||
| `expressionX`:: | ||
| An expression that computes an aggregated value. If its name coincides with one | ||
| of the computed columns, that column will be ignored. | ||
|
|
||
| `grouping_expressionX`:: | ||
| An expression that outputs the values to group by. | ||
|
nik9000 marked this conversation as resolved.
|
||
|
|
||
| NOTE: Individual `null` values are skipped when computing aggregations. | ||
|
|
||
| *Description* | ||
|
|
||
| The `INLINESTATS` command calculates an aggregate result and merges that result | ||
| back into the stream of input data. Without the optional `BY` clause this will | ||
| produce a single result which is appended to each row. With a `BY` clause this | ||
| will produce one result per grouping and merge the result into the stream based on | ||
| matching group keys. | ||
|
|
||
| All of the <<esql-agg-functions,aggregation functions>> are supported. | ||
|
|
||
| *Examples* | ||
|
|
||
| Find the employees that speak the most languages (it's a tie!): | ||
|
|
||
| [source.merge.styled,esql] | ||
| ---- | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=max-languages] | ||
| ---- | ||
| [%header.monospaced.styled,format=dsv,separator=|] | ||
| |=== | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=max-languages-result] | ||
| |=== | ||
|
|
||
| Find the longest tenured employee who's last name starts with each letter of the alphabet: | ||
|
|
||
| [source.merge.styled,esql] | ||
| ---- | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=longest-tenured-by-first] | ||
| ---- | ||
| [%header.monospaced.styled,format=dsv,separator=|] | ||
| |=== | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=longest-tenured-by-first-result] | ||
| |=== | ||
|
|
||
| Find the northern and southern most airports: | ||
|
|
||
| [source.merge.styled,esql] | ||
| ---- | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=extreme-airports] | ||
| ---- | ||
| [%header.monospaced.styled,format=dsv,separator=|] | ||
| |=== | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=extreme-airports-result] | ||
| |=== | ||
|
|
||
| NOTE: Our test data doesn't have many "small" airports. | ||
|
|
||
| If a `BY` field is multivalued then `INLINESTATS` will put the row in *each* | ||
| bucket like <<esql-stats-by>>: | ||
|
|
||
| [source.merge.styled,esql] | ||
| ---- | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=mv-group] | ||
| ---- | ||
| [%header.monospaced.styled,format=dsv,separator=|] | ||
| |=== | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=mv-group-result] | ||
| |=== | ||
|
|
||
| To treat each group key as its own row use <<esql-mv_expand>> before `INLINESTATS`: | ||
|
|
||
| [source.merge.styled,esql] | ||
| ---- | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=mv-expand] | ||
| ---- | ||
| [%header.monospaced.styled,format=dsv,separator=|] | ||
| |=== | ||
| include::{esql-specs}/inlinestats.csv-spec[tag=mv-expand-result] | ||
| |=== | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.