Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
flatten
// Generate the nested array using the function "array_repeat".
val arr_repeat_df = df.withColumn("repeat", array_repeat($"array_col2", 2))
// flatten the nested array.
val arr_flat_df = arr_repeat_df
.withColumn("result", flatten($"repeat")).select("repeat", "result")
.select("repeat", "result")
arr_flat_df.show(truncate=false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment