简体   繁体   English

读取文件时 scala 项目出错:原因:java.io.IOException:方案没有文件系统:文件

[英]Error in scala project while reading file : Caused by: java.io.IOException: No FileSystem for scheme: file

I have researched on google but did not found the solution, hence posting it here.我在谷歌上进行了研究,但没有找到解决方案,因此将其发布在这里。

val a_spark: SparkSession = SparkUtils.getSparkInstance("abc")

filepath : /Users/user1/Documents/input/demo.xml

using above variables in below method在以下方法中使用上述变量

def getDataFrame(a_spark: SparkSession, filePath: String): DataFrame = {
    a_spark.read
      .format("com.databricks.spark.xml")
      .option("rootTag", "PlaceList")
      .option("rowTag", "Place")
      .load(filePath) //error on this line
  }

Exception in thread "main" java.lang.ExceptionInInitializerError
    at Main$.delayedEndpoint$Main$1(Main.scala:8)
    at Main$delayedInit$body.apply(Main.scala:3)
    at scala.Function0.apply$mcV$sp(Function0.scala:39)
    at scala.Function0.apply$mcV$sp$(Function0.scala:39)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
    at scala.App.$anonfun$main$1$adapted(App.scala:80)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.App.main(App.scala:80)
    at scala.App.main$(App.scala:78)
    at Main$.main(Main.scala:3)
    at Main.main(Main.scala)
Caused by: java.io.IOException: No FileSystem for scheme: file
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2586)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2593)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:91)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2632)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2614)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:370)
    at org.apache.hadoop.fs.FileSystem.getLocal(FileSystem.java:341)
    at org.apache.spark.SparkContext.$anonfun$newAPIHadoopFile$2(SparkContext.scala:1151)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
    at org.apache.spark.SparkContext.withScope(SparkContext.scala:699)
    at org.apache.spark.SparkContext.newAPIHadoopFile(SparkContext.scala:1146)
    at com.databricks.spark.xml.util.XmlFile$.withCharset(XmlFile.scala:46)
    at com.databricks.spark.xml.DefaultSource.$anonfun$createRelation$1(DefaultSource.scala:71)
    at com.databricks.spark.xml.XmlRelation.$anonfun$schema$1(XmlRelation.scala:43)
    at scala.Option.getOrElse(Option.scala:189)
    at com.databricks.spark.xml.XmlRelation.<init>(XmlRelation.scala:42)
    at com.databricks.spark.xml.XmlRelation$.apply(XmlRelation.scala:29)
    at com.databricks.spark.xml.DefaultSource.createRelation(DefaultSource.scala:74)
    at com.databricks.spark.xml.DefaultSource.createRelation(DefaultSource.scala:52)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:318)
    at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)
    at util.SparkUtils$.getDataFrame(SparkUtils.scala:26)

tried adding file:// prefix at the beginning of filepath but after ading that also I am getting same error.尝试在文件路径的开头添加 file:// 前缀,但在添加之后我也遇到了同样的错误。

solution to this question is adding filesystem configurations in sparksession.这个问题的解决方案是在 sparksession 中添加文件系统配置。

object IdentifyData {

  val m_spark: SparkSession = SparkUtils.getSparkInstance("name1")

  val hadoopConfig: Configuration = m_spark.sparkContext.hadoopConfiguration
  hadoopConfig.set("fs.hdfs.impl", classOf[org.apache.hadoop.hdfs.DistributedFileSystem].getName)
  hadoopConfig.set("fs.file.impl", classOf[org.apache.hadoop.fs.LocalFileSystem].getName)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.IOException:方案的无文件系统:hdfs - java.io.IOException: No FileSystem for scheme : hdfs 原因:java.io.IOException:文件已存在 - Caused by: java.io.IOException: File already exists java.io.IOException:无法运行程序“ scala”:CreateProcess错误= 2, - java.io.IOException: Cannot run program “scala”: CreateProcess error=2, sc.textFile() 在运行命令以获取文件权限时出错:java.io.IOException: (null) entry in command string - sc.textFile() gives Error while running command to get file permissions : java.io.IOException: (null) entry in command string scala io 在读取文件时抛出错误 - scala io throws error while reading a file java.io.IOException:没有用于scheme的FileSystem:maprfs。 将maprfs jar添加到bash_profile无效 - java.io.IOException: No FileSystem for scheme: maprfs. Adding the maprfs jar to bash_profile didn't work 在windwos中,scala本地构建失败,出现java.io.IOException:无法运行程序“哪个”错误 - scala-native build failed in windwos with java.io.IOException: Cannot run program “which” error Scala Play 2.3.5-Coveralls sbt插件java.io.IOException:无法下载JavaScript - Scala Play 2.3.5 - Coveralls sbt plugin java.io.IOException: Unable to download JavaScript SBT发布未将jar文件上传到工件(发布)java.io.IOException:对URL的PUT操作失败,状态码为400:错误的请求 - SBT publish is not uploading jar file to artifactory (publish) java.io.IOException: PUT operation to URL failed with status code 400: Bad Request 在 Spark 中读取 CSV 文件时出错 - Scala - Error while reading a CSV file in Spark - Scala
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM