-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Merge pull request #1 from Yury-Fridlyand/dev-update-sql-relevance-docs Update SQL plugin relevance functions documentation. Co-authored-by: MaxKsyunz <[email protected]> Signed-off-by: Yury Fridlyand <[email protected]> * Address PR feedback. Signed-off-by: Yury Fridlyand <[email protected]> * Address PR feedback by @joshuali925. Signed-off-by: Yury Fridlyand <[email protected]> * Remove PPL page from Observability Plugin. Add link to Observability page. Make some simple formatting changes Signed-off-by: Naarcha-AWS <[email protected]> * Reword paragraph Signed-off-by: Naarcha-AWS <[email protected]> * Adds SQL and PPL API and other SQL plugin changes Signed-off-by: Fanit Kolchina <[email protected]> * Formatting changes Signed-off-by: Fanit Kolchina <[email protected]> * Incorporates editorial comments Signed-off-by: Fanit Kolchina <[email protected]> Signed-off-by: Yury Fridlyand <[email protected]> Signed-off-by: Naarcha-AWS <[email protected]> Signed-off-by: Fanit Kolchina <[email protected]> Co-authored-by: Yury Fridlyand <[email protected]> Co-authored-by: MaxKsyunz <[email protected]> Co-authored-by: Fanit Kolchina <[email protected]> (cherry picked from commit c69f860)
- Loading branch information
1 parent
de6a8ed
commit 644cbb5
Showing
41 changed files
with
2,097 additions
and
1,357 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,52 +1,91 @@ | ||
--- | ||
layout: default | ||
title: Aggregation Functions | ||
title: Aggregate Functions | ||
parent: SQL | ||
nav_order: 11 | ||
--- | ||
|
||
# Aggregation functions | ||
# Aggregate functions | ||
|
||
Aggregate functions use the `GROUP BY` clause to group sets of values into subsets. | ||
|
||
OpenSearch supports the following aggregate functions: | ||
|
||
Function | Description | ||
:--- | :--- | ||
AVG | Returns the average of the results. | ||
COUNT | Returns the number of results. | ||
SUM | Returns the sum of the results. | ||
MIN | Returns the minimum of the results. | ||
MAX | Returns the maximum of the results. | ||
VAR_POP or VARIANCE | Returns the population variance of the results after discarding nulls. | ||
VAR_SAMP | Returns the sample variance of the results after discarding nulls. | ||
STD or STDDEV | Returns the sample standard deviation of the results. Returns 0 when it has only one row of results. | ||
STDDEV_POP | Returns the population standard deviation of the results. | ||
STDDEV_SAMP | Returns the sample standard deviation of the results. Returns null when it has only one row of results. | ||
|
||
|
||
The examples below reference an `accounts` table. You can try out the examples by indexing the following documents into OpenSearch using the bulk index operation: | ||
|
||
```json | ||
```json | ||
PUT accounts/_bulk?refresh | ||
{"index":{"_id":"1"}} | ||
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"[email protected]","city":"Brogan","state":"IL","acct_open_date":"2008-01-23"} | ||
{"index":{"_id":"6"}} | ||
{"account_number":6,"balance":5686,"firstname":"Hattie","lastname":"Bond","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"[email protected]","city":"Dante","state":"TN","acct_open_date":"2008-06-07"} | ||
{"index":{"_id":"13"}} | ||
{"account_number":13,"balance":32838,"firstname":"Nanette","lastname":"Bates","age":28,"gender":"F","address":"789 Madison Street","employer":"Quility","email":"[email protected]","city":"Nogal","state":"VA","acct_open_date":"2010-04-11"} | ||
{"index":{"_id":"18"}} | ||
{"account_number":18,"balance":4180,"firstname":"Dale","lastname":"Adams","age":33,"gender":"M","address":"467 Hutchinson Court","email":"[email protected]","city":"Orick","state":"MD","acct_open_date":"2022-11-05"} | ||
``` | ||
|
||
|
||
|
||
## Group By | ||
|
||
Use the `GROUP BY` clause as an identifier, ordinal, or expression. | ||
|
||
### Identifier | ||
|
||
The following query returns the gender and average age of customers in the `accounts` index and groups the results by gender: | ||
|
||
```sql | ||
SELECT gender, sum(age) FROM accounts GROUP BY gender; | ||
SELECT gender, avg(age) FROM accounts GROUP BY gender; | ||
``` | ||
|
||
| gender | sum (age) | ||
| gender | avg(age) | ||
:--- | :--- | ||
F | 28 | | ||
M | 101 | | ||
F | 28.0 | | ||
M | 33.666666666666664 | | ||
|
||
### Ordinal | ||
|
||
The following query returns the gender and average age of customers in the `accounts` index. It groups the results by the first column of the result set, which in this case is `gender`: | ||
|
||
```sql | ||
SELECT gender, sum(age) FROM accounts GROUP BY 1; | ||
SELECT gender, avg(age) FROM accounts GROUP BY 1; | ||
``` | ||
|
||
| gender | sum (age) | ||
:--- | :--- | ||
F | 28 | | ||
M | 101 | | ||
F | 28.0 | | ||
M | 33.666666666666664 | | ||
|
||
### Expression | ||
|
||
The following query | ||
|
||
```sql | ||
SELECT abs(account_number), sum(age) FROM accounts GROUP BY abs(account_number); | ||
SELECT abs(account_number), avg(age) FROM accounts GROUP BY abs(account_number); | ||
``` | ||
|
||
| abs(account_number) | sum (age) | ||
| abs(account_number) | avg(age) | ||
:--- | :--- | ||
| 1 | 32 | | ||
| 13 | 28 | | ||
| 18 | 33 | | ||
| 6 | 36 | | ||
| 1 | 32.0 | | ||
| 13 | 28.0 | | ||
| 18 | 33.0 | | ||
| 6 | 36.0 | | ||
|
||
## Aggregation | ||
|
||
|
Oops, something went wrong.