如何编写和使用Ruby从Hadoop的HDFS /读文件? [英] How to write and read files in/from Hadoop HDFS using Ruby?

查看:207
本文介绍了如何编写和使用Ruby从Hadoop的HDFS /读文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法使用Ruby的HDFS API来工作?正如我可以理解没有多语言文件API,唯一的方法是使用原生的Java API。我试着使用JRuby,但这个解决方案是不稳定的,而不是非常原始。此外,我看着HDFS节俭API,但它没有完成,也缺乏许多功能(如写入索引文件)。

Is there a way to work with HDFS Api using Ruby? As I can understand there is no multilanguage file Api and the only way is to use native Java Api. I tried using JRuby but this solution is to unstable and not very native. Also I looked at HDFS Thrift Api but it's not complete and also lacks many features (like writing to indexed files).

有没有一种方法,除了使用与使用Ruby HDFS工作的JRuby或储蓄API?

Is there a way to work with HDFS using Ruby besides from using JRuby or Thrift Api?

推荐答案

有在GitHub上两个项目适合你的要求。 红宝石HDFS 提供了原生的C绑定HDFS为Ruby。 ganapati 与节俭服务器接口。

There are two projects in github that fit what you're asking. ruby-hdfs provides native C bindings to HDFS for Ruby. ganapati interfaces with a Thrift server.

您也可以让系统直接调用到文件系统shell 。例如:

You could also make system calls directly to the file system shell. For example:

cmd = "hadoop fs -mkdir #{hdfs_path}"
cmd += " 2> /dev/null"
system(cmd)
if $? == 0
  puts 'ok'
  exit(0)
else
  puts "Error: failed to create hdfs://#{hdfs_path}"
  exit(2)
end

这篇关于如何编写和使用Ruby从Hadoop的HDFS /读文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆