Spark 2.1.0:读取压缩的csv文件

时间:2017-04-23 00:02:40

标签: java apache-spark spark-dataframe apache-spark-mllib

我试图将压缩的csv文件(.bz2)作为DataFrame读取。我的代码如下

// read the data
    Dataset<Row> rData = spark.read().option("header", true).csv(input);

当我在IDE中尝试时,这是有效的。我可以读取数据并处理它,但是当我尝试使用maven构建它并在命令行上运行时,我收到以下错误

    Exception in thread "main" java.lang.ClassNotFoundException: Failed to find data source: csv. Please find packages at http://spark.apache.org/third-party-projects.html
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:569)
    at org.apache.spark.sql.execution.datasources.DataSource.providingClass$lzycompute(DataSource.scala:86)
    at org.apache.spark.sql.execution.datasources.DataSource.providingClass(DataSource.scala:86)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:325)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:152)
    at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:415)
    at org.apache.spark.sql.DataFrameReader.csv(DataFrameReader.scala:352)
    at com.cs6240.Driver.main(Driver.java:28)
Caused by: java.lang.ClassNotFoundException: csv.DefaultSource
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25$$anonfun$apply$13.apply(DataSource.scala:554)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25$$anonfun$apply$13.apply(DataSource.scala:554)
    at scala.util.Try$.apply(Try.scala:192)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554)
    at scala.util.Try.orElse(Try.scala:84)
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:554)
    ... 7 more

我不确定我是否在这里遗漏了一些东西。读取csv文件有一些依赖吗?根据文档,Spark 2.x.x内置了对此的支持。

1 个答案:

答案 0 :(得分:1)

我按照此答案中的步骤解决了问题。 https://stackoverflow.com/a/39465892/2705924

基本上,程序集插件存在一些问题,当我使用了shade插件并使用了这个

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>