【发布时间】:2020-05-24 05:47:07
【问题描述】:
我是 R 新手。我正在尝试在 R Studio 中运行地图缩减程序。我已经使用此命令查看文件是否存在 Hadoop fs -ls ,我可以看到文件存在于那里。但是当我尝试运行代码时,我遇到了错误。我的文件存在于这个目录 home/hduser/mr 中,我创建了另一个名为 out 的文件夹来保存输出。
**.20/05/23 11:58:30 ERROR streaming.StreamJob:启动作业时出错:输入路径不存在: hdfs://localhost:54310/user/hduser/testsong.cvs 流式传输命令 失败!
mr 中的错误(map = map,reduce = reduce,combine = combine, vectorized.reduce, : hadoop 流式传输失败,错误代码为 5**
这是我的代码。
Sys.setenv("HADOOP_CMD"="/usr/local/hadoop/bin/hadoop")
Sys.setenv(HADOOP_STREAMING="/usr/local/hadoop/share/hadoop/tools/lib/hadoop-streaming-2.6.5.jar")
library(rmr2)
library(rhdfs)
hdfs.init()
map <- function(k,lines) {
words.list <- strsplit(lines, '\\s')
words <- unlist(words.list)
return( keyval(words, 1) )
}
reduce <- function(word, counts) {
keyval(word, sum(counts))
}
wordcount <- function (input, output=NULL) {
mapreduce(input=input, output=output, input.format="csv", map=map, reduce=reduce)
}
## read text files from folder
hdfs.root <- 'home/hduser/mr'
hdfs.data <- file.path(hdfs.root, 'testsong')
hdfs.out <- file.path(hdfs.root, 'home/hduser/mr/out')
## Submit job
out <- wordcount(hdfs.data, hdfs.out)
## Fetch results from HDFS
results <- from.dfs(out)
results.df <- as.data.frame(results, stringsAsFactors=F)
colnames(results.df) <- c('word', 'count')
head(results.df)
【问题讨论】: