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

后端 未结 2 557
甜味超标
甜味超标 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]
    
    0 讨论(0)
  • 2021-01-15 14:43

    FYI I have created a Spark bug about this issue and they are fixing it https://issues.apache.org/jira/browse/SPARK-22442

    0 讨论(0)
提交回复
热议问题