我在spark中运行以下代码。
scala>import com.databricks.spark.xml.XmlInputFormat
scala>import org.apache.hadoop.io._
scala>sc.hadoopConfiguration.set(XmlInputFormat.START_TAG_KEY,"<mytag>")
scala>sc.hadoopConfiguration.set(XmlInputFormat.END_TAG_KEY,"</mytag>")
scala>sc.hadoopConfiguration.set(XmlInputFormat.ENCODING_KEY,"utf-8")
scala>val record1 = sc.newAPIHadoopFile("file:///home/myuser/myfile.xml", classOf[XmlInputFormat], classOf[LongWritable],classOf[Text])当我通过将master设置为local来运行它时,它工作得很好。
spark2-shell --jars spark-xml_2.10-0.4.1.jar --master local[*]但是当我尝试在yarn中运行它时,它返回java.io.FileNotFoundException: File file:/home/myuser/myfile.xml does not exist。
spark2-shell --jars spark-xml_2.10-0.4.1.jar --master yarn我尝试将--deply-mode添加为client和cluster,但没有成功。
发布于 2018-08-23 02:30:46
此文件file:///home/myuser/myfile.xml"似乎只能在您的驱动程序上访问,但不能在您的执行器上访问。A)手动读取HDFS上的文件并从中读取
或者B)使用spark2-shell的--files选项,它会自动将文件上传到HDFS:
spark2-shell --files /home/myuser/myfile.xml --jars spark-xml_2.10-0.4.1.jar --master yar然后
val record1 = sc.newAPIHadoopFile(org.apache.spark.SparkFiles.get("myfile.xml"), classOf[XmlInputFormat], classOf[LongWritable],classOf[Text])https://stackoverflow.com/questions/51962954
复制相似问题