You need to expand the map into two columns and cast the rows as Person
.
val rdd = sc.parallelize(Seq(Map(
("FirstName" -> "Michael"),
("SecondName" -> "Jackson")
)))
val df = rdd.toDF("person").select("person.FirstName", "person.SecondName").as[Person]
Then you can get the FullName using map
, for example:
df.map(r => r.FullName).show
+--------------+
| value|
+--------------+
|MichaelJackson|
+--------------+
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…