pyspark.sql.functions.inline_outer#
- pyspark.sql.functions.inline_outer(col)[source]#
Explodes an array of structs into a table. Unlike inline, if the array is null or empty then null is produced for each nested column.
New in version 3.4.0.
- Parameters
- col
Column
or column name input column of values to explode.
- col
- Returns
Column
generator expression with the inline exploded result.
See also
Notes
Supports Spark Connect.
Examples
>>> from pyspark.sql import functions as sf >>> df = spark.sql('SELECT * FROM VALUES (1,ARRAY(NAMED_STRUCT("a",1,"b",2), NULL, NAMED_STRUCT("a",3,"b",4))), (2,ARRAY()), (3,NULL) AS t(i,s)') >>> df.printSchema() root |-- i: integer (nullable = false) |-- s: array (nullable = true) | |-- element: struct (containsNull = true) | | |-- a: integer (nullable = false) | | |-- b: integer (nullable = false)
>>> df.select('*', sf.inline_outer('s')).show(truncate=False) +---+----------------------+----+----+ |i |s |a |b | +---+----------------------+----+----+ |1 |[{1, 2}, NULL, {3, 4}]|1 |2 | |1 |[{1, 2}, NULL, {3, 4}]|NULL|NULL| |1 |[{1, 2}, NULL, {3, 4}]|3 |4 | |2 |[] |NULL|NULL| |3 |NULL |NULL|NULL| +---+----------------------+----+----+