简体   繁体   English

如何使用Ruby在Hadoop HDFS中编写和读取文件?

[英]How to write and read files in/from Hadoop HDFS using Ruby?

Is there a way to work with HDFS Api using Ruby? 有没有办法使用Ruby使用HDFS Api? As I can understand there is no multilanguage file Api and the only way is to use native Java Api. 据我所知,没有多语言文件Api,唯一的方法是使用本机Java Api。 I tried using JRuby but this solution is to unstable and not very native. 我尝试使用JRuby,但这个解决方案是不稳定的,而不是非常原生的。 Also I looked at HDFS Thrift Api but it's not complete and also lacks many features (like writing to indexed files). 另外我看了HDFS Thrift Api,但它不完整,也缺少很多功能(比如写入索引文件)。

Is there a way to work with HDFS using Ruby besides from using JRuby or Thrift Api? 除了使用JRuby或Thrift Api之外,有没有办法使用Ruby使用HDFS?

There are two projects in github that fit what you're asking. github中有两个项目符合您的要求。 ruby-hdfs provides native C bindings to HDFS for Ruby. ruby-hdfs为Ruby的HDFS提供本机C绑定。 ganapati interfaces with a Thrift server. ganapati与Thrift服务器接口。

You could also make system calls directly to the file system shell . 您还可以直接对文件系统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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM