【问题标题】:Go client for Hadoop StreamingHadoop Streaming 的 Go 客户端
【发布时间】:2013-05-22 18:12:11
【问题描述】:

是否有众所周知的支持 Hadoop Streaming 的 Go 编程语言客户端?我四处寻找,找不到任何有价值的东西。

【问题讨论】:

    标签: hadoop go hadoop-streaming


    【解决方案1】:

    您可以直接在 Go 上运行 Hadoop 流式作业,我听说有人这样做,这里有一个示例 taken from a blog 在 Go 中进行 Wordcount。这是映射器:

    
    package main
    
    import (
            "bufio"
            "fmt"
            "os"
            "regexp"
    )
    
    func main() {
            /* Word regular experssion. */
            re, _ := regexp.Compile("[a-zA-Z0-9]+")
            reader := bufio.NewReader(os.Stdin)
    
            for {
                    line, _, err := reader.ReadLine()
                    if err != nil {
                            if err != os.EOF {
                                    fmt.Fprintf(os.Stderr, "error: can't read - %s\n", err.String())
                            }
                            break
                    }
                    matches := re.FindAll(line, -1)
                    for _, word := range(matches) {
                            fmt.Printf("%s\t1\n", word)
                    }
            }
    }
    

    这里是减速器:

    
    package main
    
    import (
            "bufio"
            "bytes"
            "fmt"
            "os"
            "strconv"
    )
    
    func main() {
            counts := make(map[string]uint)
            reader := bufio.NewReader(os.Stdin)
    
            for {
                    line, _, err := reader.ReadLine()
                    if err != nil {
                            if err != os.EOF {
                                    fmt.Fprintf(os.Stderr, "error: can't read - %s\n", err)
                            }
                            break
                    }
                    i := bytes.IndexByte(line, '\t')
                    if i == -1 {
                            fmt.Fprintln(os.Stderr, "error: can't find tab")
                            continue
                    }
                    word := string(line[0:i])
                    count, err := strconv.Atoui(string(line[i+1:]))
                    if err != nil {
                            fmt.Fprintln(os.Stderr, "error: bad number - %s\n", err)
                            continue
                    }
    
                    counts[word] = counts[word] + count
            }
    
            /* Output aggregated counts. */
            for word, count := range(counts) {
                    fmt.Printf("%s\t%d\n", word, count)
            }
    }
    

    或者,您也可以使用 dmrgo 来更轻松地编写流式作业。他们有一个可用的字数统计示例here

    我看到了另一个名为 gomrjob 的库,但它看起来维护得不是很好而且很 alpha,但如果你喜欢冒险,可以尝试一下 :)

    【讨论】:

    • 有趣。今晚我将深入研究这些链接。
    猜你喜欢
    • 1970-01-01
    • 2018-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 2014-04-10
    • 1970-01-01
    相关资源
    最近更新 更多