Mapping json to case class with Spark (spaces in the field name)

后端 未结 2 562
甜味超标
甜味超标 2021-01-15 13:56

I am trying to read a json file with the spark Dataset API, the problem is that this json contains spaces in some of the field names.

This would be a js

2条回答
  •  渐次进展
    2021-01-15 14:24

    A workaround is to create a column name without space (give underscore) & rename the DF column to match the case class column name.

    case class MyType(Field_Name: String)
    
    dataframe.withColumnRenamed("Field Name", "Field_Name").as[MyType]
    

提交回复
热议问题