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

sha*_*1dy 3 ruby api hadoop hdfs

有没有办法使用Ruby使用HDFS Api?据我所知,没有多语言文件Api,唯一的方法是使用本机Java Api.我尝试使用JRuby,但这个解决方案是不稳定的,而不是非常原生的.另外我看了HDFS Thrift Api,但它不完整,也缺少很多功能(比如写入索引文件).

除了使用JRuby或Thrift Api之外,有没有办法使用Ruby使用HDFS?

Ron*_*zer 8

github中有两个项目符合您的要求. ruby-hdfs为Ruby的HDFS提供本机C绑定. ganapati与Thrift服务器接口.

您还可以直接对文件系统shell进行系统调用.例如:

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
Run Code Online (Sandbox Code Playgroud)