我正在用spark读取一个文本文件,其模式如下。
root
|-- id: long (nullable = true)
|-- name: string (nullable = true)
|-- style: string (nullable = true)
|-- code: integer (nullable = true)
|-- state_code: integer (nullable = true)
|-- post_code: integer (nullable = true)
|-- mail: string (nullable = true)
val myDf = sqlContext.read.format("csv")
.option("header", "true")
.option("inferSchema", "false")
.schema(myschema)
.option("delimiter", "|")
.option("nullValue", "")
.option("treatEmptyValuesAsNulls", "true")
.load("Path to file")
在此输入文件中,有些coulmns的值为“\N”。我想用空(“”)重新放置所有值为“\N”的coulmn valuse。当我试着把这个数据帧写成拼花文件时
myDf.na.replace(myDf.columns.toSeq, Map("\\N" -> "")).write.format("parquet").save("path to output")
java.lang.NumberFormatException: For input string: "\N"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:12)
at java.lang.Integer.parseInt(Integer.java:80)
通过解决问题来编写拼花文件有什么帮助吗?