How to convert a case-class-based RDD into a DataFrame?
You can create a DataFrame
directly from a Seq
of case class instances using toDF
as follows:
val dogDf = Seq(Dog("Rex"), Dog("Fido")).toDF
All you need is just
val dogDF = sqlContext.createDataFrame(dogRDD)
Second parameter is part of Java API and expects you class follows java beans convention (getters/setters). Your case class doesn't follow this convention, so no property is detected, that leads to empty DataFrame with no columns.