Skip to content

Commit 7a6bcd4

Browse files
committed
docs: add examples for list_cat, list_concat, and list_repeat functions
1 parent e53d708 commit 7a6bcd4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/source/user-guide/common-operations/expressions.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,35 @@ This function returns an integer indicating the total number of elements in the
110110
111111
In this example, the `num_elements` column will contain `3` for both rows.
112112

113+
To concatenate two arrays, you can use the function :py:func:`datafusion.functions.list_cat` or :py:func:`datafusion.functions.list_concat`.
114+
These functions return a new array that is the concatenation of the input arrays.
115+
116+
.. ipython:: python
117+
118+
from datafusion import SessionContext, col
119+
from datafusion.functions import list_cat, list_concat
120+
121+
ctx = SessionContext()
122+
df = ctx.from_pydict({"a": [[1, 2, 3]], "b": [[4, 5, 6]]})
123+
df.select(list_cat(col("a"), col("b")).alias("concatenated_array"))
124+
125+
In this example, the `concatenated_array` column will contain `[1, 2, 3, 4, 5, 6]`.
126+
127+
To repeat the elements of an array a specified number of times, you can use the function :py:func:`datafusion.functions.list_repeat`.
128+
This function returns a new array with the elements repeated.
129+
130+
.. ipython:: python
131+
132+
from datafusion import SessionContext, col
133+
from datafusion.functions import list_repeat
134+
135+
ctx = SessionContext()
136+
df = ctx.from_pydict({"a": [[1, 2, 3]]})
137+
df.select(list_repeat(col("a"), 2).alias("repeated_array"))
138+
139+
In this example, the `repeated_array` column will contain `[[1, 2, 3], [1, 2, 3]]`.
140+
141+
113142
Structs
114143
-------
115144

0 commit comments

Comments
 (0)