Avramescu Cristian
Avramescu Cristian

Reputation: 67

How to create a struct from columns?

so i have a dataframe that looks like this :

 |-- id: string (nullable = true)

and i want to achieve one that looks like :

 |-- id: string (nullable = true)

How can i achieve that ? i created the case class for the second structure but i don't know to map the first dataframe.

Thanks!

Upvotes: 1

Views: 7027

Answers (1)

Ramesh Maharjan
Ramesh Maharjan

Reputation: 41957

Use struct function.

import org.apache.spark.sql.functions._
val newdf = df.select(
  $"id", struct($"os_infos", $"product_infos", $"vendor_infos") as "data")

Upvotes: 10

Related Questions