When I am trying to read a pipe separated file using Spark and scala like below:
1|Consumer Goods|101|
2|Marketing|102|
I am using the command:
val part = spark.read
.format("com.databricks.spark.csv")
.option("delimiter","|")
.load("file_name")
I am getting result as:
+---+--------------+---+----+
|_c0| _c1|_c2| _c3|
+---+--------------+---+----+
| 1|Consumer Goods|101|null|
| 2| Marketing|102|null|
+---+--------------+---+----+
Spark is reading last column which is not present in source file because of delimiter mentioned as pipe. Is there any alternative to this where I can get result as:
+---+--------------+---+
|_c0| _c1|_c2|
+---+--------------+---+
| 1|Consumer Goods|101|
| 2| Marketing|102|
+---+--------------+---+