【问题标题】:RStudio standalone connecting to HDFSRStudio 独立连接到 HDFS
【发布时间】:2015-10-27 17:32:53
【问题描述】:

我在笔记本电脑(Windown / Mac)上独立安装了 R 和 RStudio,并远程安装了 Hadoop 集群(Linux)。我想从 RStudio 连接到 HDFS 以读取数据,进行处理,最后,如果需要,将结果推送回 HDFS。

我不太确定这是否可行,或者它只需要 RStudio 的服务器版本?任何人都可以建议最好的选择吗?

谢谢

【问题讨论】:

    标签: r hadoop hdfs rstudio


    【解决方案1】:

    它是一个安全的集群吗?如果不是rwebHDFS package 解决了这个问题。使用它,您可以使用以下代码连接到远程集群:

    library(rwebhdfs)
    hdfs <- webhdfs("<hdfs-webfs-node>", 50070, "<user>")
    f <- read_file(hdfs, "/<path>/<to>/<file>")
    

    这些包依赖于 RCurl,它在与安全集群一起使用时有限制(Windows 上的 libcurl v1.0.0o)。要使用安全集群进行访问,我将使用 httr 包并使用 WebHDFS REST API 直接查询集群

    # WebHDFS url
    hdfsUri <- "http://namenodedns:port/webhdfs/v1"
    # Uri of the file you want to read
    fileUri <- "/user/username/myfile.csv"
    # Optional parameter, with the format &name1=value1&name2=value2
    optionnalParameters <- ""
    
    # OPEN => read a file
    readParameter <- "?op=OPEN"
    
    # Concatenate all the parameters into one uri
    uri <- paste0(hdfsUri, fileUri, readParameter, optionnalParameters)
    
    # Read your file with the function you want as long as it supports reading from a connection
    data <- read.csv(uri)
    

    代码直接取自link

    没有理由获取 RStudio Server。我希望这能为您指明正确的方向。

    【讨论】:

    • 两者都适合我,谢谢。第一个不返回表格,它只返回从 csv 获取的纯文本。第二个正确读取了 csv,但它并没有获取所有数据,只有 20 行,我认为有一个参数可以加载所有文件。
    猜你喜欢
    • 2018-09-04
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2019-09-24
    • 2021-05-22
    相关资源
    最近更新 更多