gpt4 book ai didi

scala - Hadoop FileUtils 无法从 Scala 在本地(Unix)文件系统上写入文件

转载 作者:可可西里 更新时间:2023-11-01 14:55:24 25 4
gpt4 key购买 nike

我正在尝试使用 org.apache.hadoop.fs 的文件系统库将文件写入本地 FileSystem。下面是我在大 scala 代码中的一个线性代码,它应该这样做,但事实并非如此。

fs.copyToLocalFile(false, hdfsSourcePath, new Path(newFile.getAbsolutePath), true)

newFile 的值为:

val newFile = new File(s"${localPath}/fileName.dat")

localPath 只是一个包含本地磁盘上完整路径的变量。hdfsSourcePath 是 HDFS 位置的完整路径。

作业正常执行,但我没有看到在本地创建的文件。我在 cluster 模式下通过 Spark 引擎运行它,这就是我使用 copyToLocalFile 方法重载 useRawLocalFileSystem 的第四个参数的原因 并将其设置为 true。使用它,我们可以避免将文件写入执行节点。

有什么想法吗?

最佳答案

I used the copyToLocalFile method which overloads the 4th argument of useRawLocalFileSystem and set it to true. Using this, we can avoid getting the files being written on the executor node.

我认为你弄错了这一点。集群模式使驱动程序运行在执行器节点上,本地文件系统是该执行器的文件系统。 useRawLocalFileSystem 仅阻止写入校验和文件 (-> info ),它不会使文件出现在提交作业的机器上,这可能是您所期望的。

您最好的办法是将文件保存到 HDFS 并在作业完成后显式检索它们。

关于scala - Hadoop FileUtils 无法从 Scala 在本地(Unix)文件系统上写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56389170/

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