Skip to content

Commit f980bdf

Browse files
committed
Update documentation of Window function and order by
1 parent 5018222 commit f980bdf

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

crates/gitql-engine/src/engine_executor.rs

-6
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,6 @@ fn execute_where_statement(
296296
return Ok(());
297297
}
298298

299-
if gitql_object.len() > 1 {
300-
gitql_object.flat()
301-
}
302-
303-
// Perform where command only on the first group
304-
// because group by command not executed yet
305299
apply_filter_operation(
306300
env,
307301
&statement.condition,

docs/expression/call.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### Call expression
2+
3+
## 1. Standard Function Calls
4+
5+
Standard functions call operate on individual rows and return a single value per row, with syntax similar to most programming languages for example
6+
7+
```sql
8+
LEN(name)
9+
LOWER(author_name)
10+
```
11+
12+
## 2. Aggregate Function Calls
13+
14+
Aggregate functions call has the same syntax like standard function call but it's operate on a set of rows (a group) and return a single value for the entire group. They are often used with the `GROUP BY` clause, the value of aggregation function can be used only after group by statement.
15+
16+
```sql
17+
SELECT author_name, COUNT(author_name) AS commit_num FROM commits GROUP BY author_name, author_email ORDER BY commit_num DESC LIMIT 10
18+
```
19+
20+
## 3. Window functions
21+
22+
Window functions perform calculations across a set of rows that are related to the current row. Unlike aggregate functions with GROUP BY, window functions do not collapse rows into a single output row. Instead, they return a value for each input row based on a "window" of related rows,
23+
in window function call you must to explicit define `OVER` clauses even if it empty, also you can use aggregation function as window function.
24+
25+
```sql
26+
SELECT emp_name, dep_name, ROW_NUMBER() OVER(PARTITION BY dep_name) AS row_number FROM emp_salaries
27+
28+
SELECT emp_name,
29+
dep_name,
30+
ROW_NUMBER() OVER partition_dep_order_salary_des AS row_number_per_department,
31+
MIN(salary) OVER partition_dep_order_salary_des AS min_salary_per_department,
32+
MAX(salary) OVER partition_dep_order_salary_des AS max_salary_per_department
33+
FROM emp_salaries
34+
WINDOW partition_dep_order_salary_des AS (PARTITION BY dep_name ORDER BY salary DESC)
35+
ORDER BY dep_name ASC NULLS LAST;
36+
```

docs/expression/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ GitQL Expressions
55
- [Case expression](case.md).
66
- [Cast expression](cast.md)
77
- [Array expression](array.md).
8-
- [Access Member](access.md).
8+
- [Access Member](access.md).
9+
- [Call expression](call.md)

docs/statement/order_by.md

+7
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ The `ORDER BY` Statement with `USING <operator>` syntax inspired by PostgreSQL
1313
```sql
1414
SELECT author_name, author_email FROM commits ORDER BY author_email, commit_id USING <
1515
SELECT author_name, author_email FROM commits ORDER BY author_name USING >
16+
```
17+
18+
You can define nulls order policy to set if you want null value to be first or last in the order
19+
20+
```sql
21+
SELECT author_name, author_email FROM commits ORDER BY author_email NULLS FIRST
22+
SELECT author_name, author_email FROM commits ORDER BY author_name NULLS LAST
1623
```

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ nav:
106106
- Case: expression/case.md
107107
- Cast: expression/cast.md
108108
- Access Member: expression/access.md
109+
- Call: expression/call.md
109110
- STD Functions and Operators:
110111
- "functions/index.md"
111112
- Logical: functions/logical.md

0 commit comments

Comments
 (0)