gpt4 book ai didi

java - Spark 2.1.0 : Reading compressed csv file

转载 作者:行者123 更新时间:2023-11-30 06:46:47 32 4
gpt4 key购买 nike

我正在尝试将压缩的 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 内置了对此的支持。

最佳答案

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

基本上,程序集插件存在一些问题,当我使用阴影插件并使用它时

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

关于java - Spark 2.1.0 : Reading compressed csv file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43565962/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com