我是这样启动 Spark 的:
spark-shell --master local[10]
我正在尝试查看底层 Hadoop 安装上的文件。
我想做这样的事情:
hdfs ls
我该怎么做?
最佳答案
只需从 sys.process 包中导入类,您就可以从 scala(spark 默认自带)执行任何底层系统/操作系统命令(如 hdfs dfs -ls 甚至纯 shell/DOS 命令)。 参见下面的例子
Linux
import sys.process._
val oldcksum = "cksum oldfile.txt" !!
val newcksum = "cksum newfile.txt" !!
val hdpFiles = "hdfs dfs -ls" !!
window
import sys.process._ # This will let underlying OS commands to be executed.
val oldhash = "certUtil -hashFile PATH_TO_FILE" !!#CertUtil is a windows command
如果您计划在 Spark 中读取和写入 HDFS,您需要首先集成 spark 和 hadoop。 http://spark.apache.org/docs/latest/configuration.html#inheriting-hadoop-cluster-configuration
关于hadoop - 如何从 Spark 中查看底层 Hadoop 文件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40530550/