Skip to content

Commit

Permalink
docs: add examples for list_cat, list_concat, and list_repeat functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kosiew committed Nov 7, 2024
1 parent e53d708 commit 7a6bcd4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/source/user-guide/common-operations/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ This function returns an integer indicating the total number of elements in the
In this example, the `num_elements` column will contain `3` for both rows.

To concatenate two arrays, you can use the function :py:func:`datafusion.functions.list_cat` or :py:func:`datafusion.functions.list_concat`.
These functions return a new array that is the concatenation of the input arrays.

.. ipython:: python
from datafusion import SessionContext, col
from datafusion.functions import list_cat, list_concat
ctx = SessionContext()
df = ctx.from_pydict({"a": [[1, 2, 3]], "b": [[4, 5, 6]]})
df.select(list_cat(col("a"), col("b")).alias("concatenated_array"))
In this example, the `concatenated_array` column will contain `[1, 2, 3, 4, 5, 6]`.

To repeat the elements of an array a specified number of times, you can use the function :py:func:`datafusion.functions.list_repeat`.
This function returns a new array with the elements repeated.

.. ipython:: python
from datafusion import SessionContext, col
from datafusion.functions import list_repeat
ctx = SessionContext()
df = ctx.from_pydict({"a": [[1, 2, 3]]})
df.select(list_repeat(col("a"), 2).alias("repeated_array"))
In this example, the `repeated_array` column will contain `[[1, 2, 3], [1, 2, 3]]`.


Structs
-------

Expand Down

0 comments on commit 7a6bcd4

Please sign in to comment.