pyspark.sql.functions.array_append

pyspark.sql.functions.array_append(col: ColumnOrName, value: Any) → pyspark.sql.column.Column[source]

Collection function: returns an array of the elements in col1 along with the added element in col2 at the last of the array.

New in version 3.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

name of column containing array

value :

a literal value, or a Column expression.

Returns
Column

an array of values from first array along with the element.

Examples

>>> from pyspark.sql import Row
>>> df = spark.createDataFrame([Row(c1=["b", "a", "c"], c2="c")])
>>> df.select(array_append(df.c1, df.c2)).collect()
[Row(array_append(c1, c2)=['b', 'a', 'c', 'c'])]
>>> df.select(array_append(df.c1, 'x')).collect()
[Row(array_append(c1, x)=['b', 'a', 'c', 'x'])]