I am using spark version 2.2. I am trying to create a dataframe with 1 column as MapType.
I have tried following things for that:
scala> val mapSeq = Seq((Map(1-> 2, 11-> 22))).toDF("num")
<console>:23: error: value toDF is not a member of Seq[scala.collection.immutable.Map[Int,Int]]
val mapSeq = Seq((Map(1-> 2, 11-> 22))).toDF("num")
and
scala> spark.createDataFrame(List(Map("a" -> "b")), StructType(MapType(StringType, StringType)))
error: overloaded method value apply with alternatives:
(fields: Array[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType <and>
(fields: java.util.List[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType <and>
(fields: Seq[org.apache.spark.sql.types.StructField])org.apache.spark.sql.types.StructType
cannot be applied to (org.apache.spark.sql.types.MapType)
spark.createDataFrame(List(Map("a" -> "b")), StructType(MapType(StringType, StringType)))
Both the methods throws error.
I tried searching and found this medium blog - https://medium.com/@mrpowers/working-with-spark-arraytype-and-maptype-columns-4d85f3c8b2b3 But it blog there is some older version of spark used.
Any Ideas on how can I create this?