Description
Currently, MapType is not supported by the from_json function as the root type. For example, the following code doesn't work on Spark 2.3:
scala> import org.apache.spark.sql.types._ import org.apache.spark.sql.types._ scala> val schema = MapType(StringType, IntegerType) schema: org.apache.spark.sql.types.MapType = MapType(StringType,IntegerType,true) scala> val in = Seq("""{"a": 1, "b": 2, "c": 3}""").toDS() in: org.apache.spark.sql.Dataset[String] = [value: string] scala> in.select(from_json($"value", schema, Map[String, String]())).collect() org.apache.spark.sql.AnalysisException: cannot resolve 'jsontostructs(`value`)' due to data type mismatch: Input schema map<string,int> must be a struct or an array of structs.
Purpose of the ticket is to support MapType with StringType as keys type.