【问题标题】:R Reducer is not working properly in Amazon EMRR Reducer 在 Amazon EMR 中无法正常工作
【发布时间】:2014-06-26 03:26:42
【问题描述】:

我在 R 中编写了一个 map reduce 代码,以便在 Amazon EMR 中运行。

我的输入文件格式: URL1 word1 word2 word3 URL2 word4 word2 word3 URL3 word1 word7 word2

我期望输出为:URLs are concat with spaces word1 URL1 URL3 word2 URL1 URL2 URL3 word3 URL1 URL2 .. ... ..

但 EMR 使用 3 个 reducer 并创建 3 个输出文件。文件明智的输出是正确的,它正在组合值,没有重复的键。但是如果我们一起查看这 3 个文件,就会发现有重复的键。

输出文件 1: word1 URL1 URL3 word2 URL1 .. ..

输出文件 2: word2 URL2 URL3 word3 URL1 .. ..

看,word2 被分发到 2 个文件中。我需要一把钥匙在一个文件里。

我正在使用 EMR 中的 Hadoop Streaming。请建议我正确设置以删除不同文件中的重复键。

我认为我的映射器工作正常。这是我的减速机:

process <- function(mat){

rows = nrow(mat)
cols = ncol(mat)

for(i in 1:rows)
{

    for(j in i+1:rows)
    {
        if(j<=rows)
        {
            if(toString(mat[i,1])==toString(mat[j,1]))
            {
            x<-paste(mat[i,2],mat[j,2],sep=" ")
            mat[i,2]=x
            mat<-mat[-j,]
            rows<-rows-1
            }
        }
    }
}

write.table(mat, file=stdout(), quote=FALSE, row.names=FALSE, col.names=FALSE)
}

reduce <- function(input){
  #create column names to make is easier to work with the data set
  names <- c("word", "value")
  cols = as.list(vector(length=2, mode="character"))
  names(cols) <- names

  #read from the input
  hsTableReader(file=input, cols, ignoreKey=TRUE, chunkSize=100000, FUN=process, sep=" ")


}

【问题讨论】:

  • 你能分享你正在运行的代码吗?

标签: r hadoop mapreduce elastic-map-reduce emr


【解决方案1】:

您是否尝试过使用组合器将相同的键收集到同一个减速器中?这样,您应该能够将具有相似键的所有单词收集到单个减速器中。使用组合器检查一些 wordcount 示例,以了解组合器类的工作原理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 2020-03-26
    • 1970-01-01
    • 2021-10-31
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    相关资源
    最近更新 更多