Проверьте код ниже.
value
как String
scala> val df = Seq(("key","""[{"field1": "value1", "field2": "value2"}]""")).toDF("key","value")
df: org.apache.spark.sql.DataFrame = [key: string, value: string]
scala> import org.apache.spark.sql.types._
import org.apache.spark.sql.types._
scala> val schema = ArrayType(MapType(StringType,StringType))
schema: org.apache.spark.sql.types.ArrayType = ArrayType(MapType(StringType,StringType,true),true)
scala> df.select($"key",explode(from_json($"value",schema)).as("value")).select($"value"("field1").as("field1"),$"value"("field2").as("field2")).show(false)
+------+------+
|field1|field2|
+------+------+
|value1|value2|
+------+------+
value
как Map
scala> val df = Seq(("key",Seq(Map("field1" -> "value1","field2" -> "value2")))).toDF("key","value")
df: org.apache.spark.sql.DataFrame = [key: string, value: array<map<string,string>>]
scala> df.select($"key",explode($"value").as("value")).select($"value"("field1").as("field1"),$"value"("field2").as("field2")).show(false)
+------+------+
|field1|field2|
+------+------+
|value1|value2|
+------+------+