Spark Q&A : Spark利用databricks读取CSV文件报错 CSVFormat NoClassDefFoundError
2017-05-23 11:19
309 查看
Q: Spark使用databricks进行csv文件读取的时候报错
A: 根据kevinskii在Github上的回答,该问题出现的原因是在于spark-csv的jar文件中没有添加CSVFormat的依赖. 解决办法是下载common-csv的jar包并通过 -jar 添加到spark-submit的任务中.
It seems that the org/apache/commons/csv/CSVFormat dependency isn’t being packaged in the spark-csv jar file. Downloading the binary from (https://commons.apache.org/proper/commons-csv/download_csv.cgi), extracting the .jar from it and setting the permissions, and finally including it in the list of comma-separated JAR files following the “–jar” option when running the Spark shell solved it for me.
Example:
bin/pyspark –jars /path/to/spark-csv.jar,/path/to/commons-csv.jar
同时, m-mashaye在stackoverflow上给出了用textFile读取csv文件,并通过
Instead of using sqlContext.read, I used the following code to turn my .csv file into a dataframe. Suppose the .csv file has 5 columns as follow:
java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat,找不到对应的CSVFormat类.
A: 根据kevinskii在Github上的回答,该问题出现的原因是在于spark-csv的jar文件中没有添加CSVFormat的依赖. 解决办法是下载common-csv的jar包并通过 -jar 添加到spark-submit的任务中.
It seems that the org/apache/commons/csv/CSVFormat dependency isn’t being packaged in the spark-csv jar file. Downloading the binary from (https://commons.apache.org/proper/commons-csv/download_csv.cgi), extracting the .jar from it and setting the permissions, and finally including it in the list of comma-separated JAR files following the “–jar” option when running the Spark shell solved it for me.
Example:
bin/pyspark –jars /path/to/spark-csv.jar,/path/to/commons-csv.jar
同时, m-mashaye在stackoverflow上给出了用textFile读取csv文件,并通过
case class构建DF的解决办法, 适用于尝试过各种办法但是仍不能解决问题的绝望者.
Instead of using sqlContext.read, I used the following code to turn my .csv file into a dataframe. Suppose the .csv file has 5 columns as follow:
// Define case class case class Flight(arrDelay: Int, depDelay: Int, origin: String, dest: String, distance: Int) // Then val flights=sc.textFile("2008.csv").map(_.split(",")).map(p => Flight(p(0).trim.toInt, p(1).trim.toInt, p(2) , p(3), p(4).trim.toInt)).toDF()
相关文章推荐
- Spark Q&A : Spark利用databricks读取CSV文件报错 CSVFormat NoClassDefFoundError
- jackson-data-format-csv 读取csv文件——高级配置及原理解析
- 利用jackson-dataformat-csv读写csv文件
- access利用vba读取csv文件
- SparkR读取CSV格式文件错误java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.spark.u
- JMeter 参数化之利用CSV Data Set Config从文件读取参数并关联变量
- 利用LOAD DATA将csv文件中的数据导入MySQL
- 利用php CI force_download($filename, $data) 下载.csv 文件解决文件名乱码,文件内容乱码
- java web 利用 commons-fileupload-1.2 实现文件上传 解决 中文乱码& 非文件属性的读取
- Spark创建DataFrame和读取CSV数据文件
- spark2.x读取csv格式文件
- Python使用pandas & pymysql读取MySQL数据到csv文件中
- 离线轻量级大数据平台Spark之读取CSV文件实例
- SpringMVC从数据库导入导出 CSV文件(利用multipart/form-data实现文件上传)
- Java+Selenium3方法篇44-利用opencsv读取csv文件
- 利用ADO读取CSV文件
- 利用php CI force_download($filename, $data) 下载.csv 文件解决文件名乱码,文件内容乱码
- spark读取csv文件
- Spark创建DataFrame和读取CSV数据文件
- 利用pandas模块读取csv文件和excel表格,并用matplotlib画图