How to convert a case-class-based RDD into a DataFrame?

后端 未结 3 1599
暗喜
暗喜 2021-01-04 08:33

The Spark documentation shows how to create a DataFrame from an RDD, using Scala case classes to infer a schema. I am trying to reproduce this concept using sqlContext

3条回答
  •  时光说笑
    2021-01-04 08:38

    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.

提交回复
热议问题