I'm trying to convert a val rec: RDD[Map[String, String]] into a Spark dataframe.
But when I execute:
val sqlContext = new SQLContext(sc)
val df = sqlContext.createDataFrame(rec, classOf[Map[String, String]])
df.write.json("/tmp/file.json")
The file json is full of empty objects:
{}
{}
{}
{}
{}
I'm converting it to json just because I want save the rec val and reuse it later with SQLContext object in python.
So the question is how to save my RDD[HashMap[String, String]] created in Scala and reuse later in Python?
UPDATE
rec val contains
Map(Param_timestamp -> 2017-03-28T02:00:02.887, Param_querytype -> listing, Param_slug -> /salute-beauty-fitness/bellezza-cura-del-corpo/cosmesi/makeup, Param_br -> CAUDALIE)
df.show() returns:
++
||
++
||
... all the 20 lines are the alike "||"
||
++
only showing top 20 rows
rec? And what is the output ofdf.show()? - L. CWIStructType( StructField("timeStamp", StringType, false) :: StructField("querytype", StringType, false) :: StructField("slug", StringType, false):: StructField("br", StringType, false) :: Nil)inside your createDataframe? (I don't know much about scala, but somehhow you need to specify the schema when creating your dataframe, and since it's empty I would think the wrong schema is used here) - Adonis