0

I have a spark dataframe as

enter image description here

with schema

StructType(structField("a",IntegerType,False),structField("b",IntegerType,False),structField("c",ArrayType(structType(structField("d",IntegerType,False),structField("e",IntegerType,False)))

I want to create a separate dataframe from column "c" which is of array type.

Desired output format is

enter image description here

3
  • look into the explode function :) Commented Aug 25, 2020 at 15:17
  • @GamingFelix Thanks for your help. Explode is not dynamically creating separate columns. Can you please help me with exact syntax you are referring to, where you can have n number of columns in array. Commented Aug 25, 2020 at 15:53
  • Hi! does this help stackoverflow.com/questions/51609740/… ? Commented Aug 25, 2020 at 19:04

1 Answer 1

1

Try this-

df.selectExpr("a", "b", "inline_outer(c)").show()
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. this is really useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.