Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit fbb785d

Browse files
Merge pull request #11 from opendistro/master
merge
2 parents d9bbf68 + 67ac19c commit fbb785d

File tree

4 files changed

+155
-3
lines changed

4 files changed

+155
-3
lines changed

docs/images/sample-notebook.png

1.73 MB
Loading

docs/notebooks/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ You can perform the following actions on paragraphs:
6262
- Clear the outputs of all paragraphs.
6363
- Delete all the paragraphs.
6464
- Move paragraphs up and down.
65+
66+
## Sample Notebook
67+
68+
![sample notebook](../images/sample-notebook.png)

docs/ppl/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
layout: default
3-
title: PPL
3+
title: Pipe Processing Language
44
nav_order: 33
55
has_children: true
66
has_toc: false
77
---
88

9-
# PPL
9+
# Pipe Processing Language
1010

11-
Piped Processing Language (PPL) is a query language that lets you use pipe (`|`) syntax to explore, discover, and query data stored in Elasticsearch.
11+
Pipe Processing Language (PPL) is a query language that lets you use pipe (`|`) syntax to explore, discover, and query data stored in Elasticsearch.
1212

1313
To quickly get up and running with PPL, use **Query Workbench** in Kibana. To learn more, see [Workbench](../sql/workbench/).
1414

docs/sql/aggregations.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
layout: default
3+
title: Aggregation Functions
4+
parent: SQL
5+
nav_order: 11
6+
---
7+
8+
# Aggregation functions
9+
10+
Aggregate functions use the `GROUP BY` clause to group sets of values into subsets.
11+
12+
## Group By
13+
14+
Use the `GROUP BY` clause as an identifier, ordinal, or expression.
15+
16+
### Identifier
17+
18+
```sql
19+
SELECT gender, sum(age) FROM accounts GROUP BY gender;
20+
```
21+
22+
| gender | sum (age)
23+
:--- | :---
24+
F | 28 |
25+
M | 101 |
26+
27+
### Ordinal
28+
29+
```sql
30+
SELECT gender, sum(age) FROM accounts GROUP BY 1;
31+
```
32+
33+
| gender | sum (age)
34+
:--- | :---
35+
F | 28 |
36+
M | 101 |
37+
38+
### Expression
39+
40+
```sql
41+
SELECT abs(account_number), sum(age) FROM accounts GROUP BY abs(account_number);
42+
```
43+
44+
| abs(account_number) | sum (age)
45+
:--- | :---
46+
| 1 | 32 |
47+
| 13 | 28 |
48+
| 18 | 33 |
49+
| 6 | 36 |
50+
51+
## Aggregation
52+
53+
Use aggregations as a select, expression, or an argument of an expression.
54+
55+
### Select
56+
57+
```sql
58+
SELECT gender, sum(age) FROM accounts GROUP BY gender;
59+
```
60+
61+
| gender | sum (age)
62+
:--- | :---
63+
F | 28 |
64+
M | 101 |
65+
66+
### Argument
67+
68+
```sql
69+
SELECT gender, sum(age) * 2 as sum2 FROM accounts GROUP BY gender;
70+
```
71+
72+
| gender | sum2
73+
:--- | :---
74+
F | 56 |
75+
M | 202 |
76+
77+
### Expression
78+
79+
```sql
80+
SELECT gender, sum(age * 2) as sum2 FROM accounts GROUP BY gender;
81+
```
82+
83+
| gender | sum2
84+
:--- | :---
85+
F | 56 |
86+
M | 202 |
87+
88+
### COUNT
89+
90+
Use the `COUNT` function to accept arguments such as a `*` or a literal like `1`.
91+
The meaning of these different forms are as follows:
92+
93+
- `COUNT(field)` - Only counts if given a field (or expression) is not null or missing in the input rows.
94+
- `COUNT(*)` - Counts the number of all its input rows.
95+
- `COUNT(1)` (same as `COUNT(*)`) - Counts any non-null literal.
96+
97+
## Having
98+
99+
Use the `HAVING` clause to filter out aggregated values.
100+
101+
### HAVING with GROUP BY
102+
103+
You can use aggregate expressions or its aliases defined in a `SELECT` clause in a `HAVING` condition.
104+
105+
We recommend using a non-aggregate expression in the `WHERE` clause although you can do this in a `HAVING` clause.
106+
107+
The aggregations in a `HAVING` clause are not necessarily the same as that in a select list. As an extension to the SQL standard, you're not restricted to using identifiers only in the `GROUP BY` list.
108+
For example:
109+
110+
```sql
111+
SELECT gender, sum(age)
112+
FROM accounts
113+
GROUP BY gender
114+
HAVING sum(age) > 100;
115+
```
116+
117+
| gender | sum (age)
118+
:--- | :---
119+
M | 101 |
120+
121+
Here's another example for using an alias in a `HAVING` condition.
122+
123+
```sql
124+
SELECT gender, sum(age) AS s
125+
FROM accounts
126+
GROUP BY gender
127+
HAVING s > 100;
128+
```
129+
130+
| gender | s
131+
:--- | :---
132+
M | 101 |
133+
134+
If an identifier is ambiguous, for example, present both as a select alias and as an index field (preference is alias). In this case, the identifier is replaced with an expression aliased in the `SELECT` clause:
135+
136+
### HAVING without GROUP BY
137+
138+
You can use a `HAVING` clause without the `GROUP BY` clause. This is useful because aggregations are not supported in a `WHERE` clause:
139+
140+
```sql
141+
SELECT 'Total of age > 100'
142+
FROM accounts
143+
HAVING sum(age) > 100;
144+
```
145+
146+
| Total of age > 100 |
147+
:--- |
148+
Total of age > 100 |

0 commit comments

Comments
 (0)