Skip to content

Commit 2d69ddb

Browse files
authored
Docs: Improve documentation for struct function` (#6754)
1 parent 878fec1 commit 2d69ddb

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

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

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,47 @@ trim_array(array, n)
16061606
Can be a constant, column, or function, and any combination of array operators.
16071607
- **n**: Element to trim the array.
16081608

1609+
## Struct Functions
1610+
1611+
- [struct](#struct)
1612+
1613+
### `struct`
1614+
1615+
Returns an Arrow struct using the specified input expressions.
1616+
Fields in the returned struct use the `cN` naming convention.
1617+
For example: `c0`, `c1`, `c2`, etc.
1618+
1619+
```
1620+
struct(expression1[, ..., expression_n])
1621+
```
1622+
1623+
For example, this query converts two columns `a` and `b` to a single column with
1624+
a struct type of fields `c0` and `c1`:
1625+
1626+
```sql
1627+
select * from t;
1628+
+---+---+
1629+
| a | b |
1630+
+---+---+
1631+
| 1 | 2 |
1632+
| 3 | 4 |
1633+
+---+---+
1634+
1635+
select struct(a, b) from t;
1636+
+-----------------+
1637+
| struct(t.a,t.b) |
1638+
+-----------------+
1639+
| {c0: 1, c1: 2} |
1640+
| {c0: 3, c1: 4} |
1641+
+-----------------+
1642+
```
1643+
1644+
#### Arguments
1645+
1646+
- **expression_n**: Expression to include in the output struct.
1647+
Can be a constant, column, or function, and any combination of arithmetic or
1648+
string operators.
1649+
16091650
## Hashing Functions
16101651

16111652
- [digest](#digest)
@@ -1708,7 +1749,6 @@ sha512(expression)
17081749

17091750
- [arrow_cast](#arrow_cast)
17101751
- [arrow_typeof](#arrow_typeof)
1711-
- [struct](#struct)
17121752

17131753
### `arrow_cast`
17141754

@@ -1739,19 +1779,3 @@ arrow_typeof(expression)
17391779
- **expression**: Expression to evaluate.
17401780
Can be a constant, column, or function, and any combination of arithmetic or
17411781
string operators.
1742-
1743-
### `struct`
1744-
1745-
Returns an Arrow struct using the specified input expressions.
1746-
Fields in the returned struct use the `cN` naming convention.
1747-
For example: `c0`, `c1`, `c2`, etc.
1748-
1749-
```
1750-
struct(expression1[, ..., expression_n])
1751-
```
1752-
1753-
#### Arguments
1754-
1755-
- **expression_n**: Expression to include in the output struct.
1756-
Can be a constant, column, or function, and any combination of arithmetic or
1757-
string operators.

0 commit comments

Comments
 (0)