本地火花群集的火花上下文



有人可以这么好心地告诉我如何调整以下代码中的hdfs URI,以便它们与我的本地火花"集群"一起工作吗?

var lines = sparkContext.TextFile(@"hdfs://path/to/input.txt");  
// some more code
wordCounts.SaveAsTextFile(@"hdfs://path/to/wordcount.txt");  

您可以只定义路径位置配置参数将在 Sparkcontext 上进行设置,因此无需添加 hdfs 就像下面这样应该可以以纱线模式运行应用程序

var lines = sparkContext.TextFile("/path/to/input.txt");  
// some more code
wordCounts.SaveAsTextFile("/path/to/wordcount.txt");  

或者你可以明确定义HDFS位置,如下所示

val lines =  sparkContext.textFile("hdfs://namenode:port/path/to/input.txt")

您还可以定义可选的分区数

var lines = sparkContext.TextFile("/path/to/input.txt",[number of partitions]);