Generate a Spark StructType / Schema from a case class

前端 未结 4 1757
情歌与酒
情歌与酒 2020-11-29 21:50

If I wanted to create a StructType (i.e. a DataFrame.schema) out of a case class, is there a way to do it without creating a Dat

4条回答
  •  感情败类
    2020-11-29 21:57

    I know this question is almost a year old but I came across it and thought others who do also might want to know that I have just learned to use this approach:

    import org.apache.spark.sql.Encoders
    val mySchema = Encoders.product[MyCaseClass].schema
    

提交回复
热议问题