pyspark.sql.functions.map_keys

pyspark.sql.functions.map_keys(col: ColumnOrName) → pyspark.sql.column.Column[source]

Collection function: Returns an unordered array containing the keys of the map.

New in version 2.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

name of column or expression

Returns
Column

keys of the map as an array.

Examples

>>> from pyspark.sql.functions import map_keys
>>> df = spark.sql("SELECT map(1, 'a', 2, 'b') as data")
>>> df.select(map_keys("data").alias("keys")).show()
+------+
|  keys|
+------+
|[1, 2]|
+------+