Skip to content

Commit 22a242c

Browse files
jonathanc-nalambcomphead
authored
docs: Added Special Functions Page (#13102)
* Added special function page * Add index entry, tweak wording * Improve example * Update docs/source/user-guide/sql/special_functions.md --------- Co-authored-by: Andrew Lamb <[email protected]> Co-authored-by: Oleks V <[email protected]>
1 parent 73cfa6c commit 22a242c

File tree

3 files changed

+101
-77
lines changed

3 files changed

+101
-77
lines changed

docs/source/user-guide/sql/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ SQL Reference
3535
window_functions_new
3636
scalar_functions
3737
scalar_functions_new
38+
special_functions
3839
sql_status
3940
write_options

docs/source/user-guide/sql/scalar_functions.md

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -72,51 +72,8 @@ See [date_part](#date_part).
7272

7373
## Array Functions
7474

75-
- [unnest](#unnest)
7675
- [range](#range)
7776

78-
### `unnest`
79-
80-
Transforms an array into rows.
81-
82-
#### Arguments
83-
84-
- **array**: Array expression to unnest.
85-
Can be a constant, column, or function, and any combination of array operators.
86-
87-
#### Examples
88-
89-
```
90-
> select unnest(make_array(1, 2, 3, 4, 5));
91-
+------------------------------------------------------------------+
92-
| unnest(make_array(Int64(1),Int64(2),Int64(3),Int64(4),Int64(5))) |
93-
+------------------------------------------------------------------+
94-
| 1 |
95-
| 2 |
96-
| 3 |
97-
| 4 |
98-
| 5 |
99-
+------------------------------------------------------------------+
100-
```
101-
102-
```
103-
> select unnest(range(0, 10));
104-
+-----------------------------------+
105-
| unnest(range(Int64(0),Int64(10))) |
106-
+-----------------------------------+
107-
| 0 |
108-
| 1 |
109-
| 2 |
110-
| 3 |
111-
| 4 |
112-
| 5 |
113-
| 6 |
114-
| 7 |
115-
| 8 |
116-
| 9 |
117-
+-----------------------------------+
118-
```
119-
12077
### `range`
12178

12279
Returns an Arrow array between start and stop with step. `SELECT range(2, 10, 3) -> [2, 5, 8]` or
@@ -165,40 +122,6 @@ are not allowed
165122

166123
- generate_series
167124

168-
## Struct Functions
169-
170-
- [unnest](#unnest-struct)
171-
172-
For more struct functions see the new documentation [
173-
`here`](https://datafusion.apache.org/user-guide/sql/scalar_functions_new.html)
174-
175-
### `unnest (struct)`
176-
177-
Unwraps struct fields into columns.
178-
179-
#### Arguments
180-
181-
- **struct**: Object expression to unnest.
182-
Can be a constant, column, or function, and any combination of object operators.
183-
184-
#### Examples
185-
186-
```
187-
> select * from foo;
188-
+---------------------+
189-
| column1 |
190-
+---------------------+
191-
| {a: 5, b: a string} |
192-
+---------------------+
193-
194-
> select unnest(column1) from foo;
195-
+-----------------------+-----------------------+
196-
| unnest(foo.column1).a | unnest(foo.column1).b |
197-
+-----------------------+-----------------------+
198-
| 5 | a string |
199-
+-----------------------+-----------------------+
200-
```
201-
202125
## Other Functions
203126

204127
See the new documentation [`here`](https://datafusion.apache.org/user-guide/sql/scalar_functions_new.html)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Special Functions
21+
22+
## Expansion Functions
23+
24+
- [unnest](#unnest)
25+
- [unnest(struct)](#unnest-struct)
26+
27+
### `unnest`
28+
29+
Expands an array or map into rows.
30+
31+
#### Arguments
32+
33+
- **array**: Array expression to unnest.
34+
Can be a constant, column, or function, and any combination of array operators.
35+
36+
#### Examples
37+
38+
```sql
39+
> select unnest(make_array(1, 2, 3, 4, 5)) as unnested;
40+
+----------+
41+
| unnested |
42+
+----------+
43+
| 1 |
44+
| 2 |
45+
| 3 |
46+
| 4 |
47+
| 5 |
48+
+----------+
49+
```
50+
51+
```sql
52+
> select unnest(range(0, 10)) as unnested_range;
53+
+----------------+
54+
| unnested_range |
55+
+----------------+
56+
| 0 |
57+
| 1 |
58+
| 2 |
59+
| 3 |
60+
| 4 |
61+
| 5 |
62+
| 6 |
63+
| 7 |
64+
| 8 |
65+
| 9 |
66+
+----------------+
67+
```
68+
69+
### `unnest (struct)`
70+
71+
Expand a struct fields into individual columns.
72+
73+
#### Arguments
74+
75+
- **struct**: Object expression to unnest.
76+
Can be a constant, column, or function, and any combination of object operators.
77+
78+
#### Examples
79+
80+
```sql
81+
> create table foo as values ({a: 5, b: 'a string'}), ({a:6, b: 'another string'});
82+
83+
> create view foov as select column1 as struct_column from foo;
84+
85+
> select * from foov;
86+
+---------------------------+
87+
| struct_column |
88+
+---------------------------+
89+
| {a: 5, b: a string} |
90+
| {a: 6, b: another string} |
91+
+---------------------------+
92+
93+
> select unnest(struct_column) from foov;
94+
+------------------------------------------+------------------------------------------+
95+
| unnest_placeholder(foov.struct_column).a | unnest_placeholder(foov.struct_column).b |
96+
+------------------------------------------+------------------------------------------+
97+
| 5 | a string |
98+
| 6 | another string |
99+
+------------------------------------------+------------------------------------------+
100+
```

0 commit comments

Comments
 (0)