hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Yu <yuzhih...@gmail.com>
Subject Re: Anyone good with JRuby?
Date Sat, 04 Oct 2014 21:22:07 GMT
Take a look at _put_internal() method of
hbase-shell//src/main/ruby/hbase/table.rb

On Sat, Oct 4, 2014 at 2:15 PM, Roger Maillist <darkchanterlist@gmail.com>
wrote:

> Hi out there
>
> I am trying to read a (binary) file from the local FS and store it in HBase
> using JRuby.
>
> But I fail with the byte-array InputStream needed for the Put-Method:
>
> require "java"
>
> java_import "java.io.File"
> java_import "java.io.FileInputStream"
>
> java_import "org.apache.hadoop.hbase.client.HTable"
> java_import "org.apache.hadoop.hbase.client.Put"
>
> def jbytes(*args)
>   args.map { |arg| arg.to_s.to_java_bytes }
> end
>
> puts "Hello from Ruby"
>
> inFile = File.new("/home/roger/Downloads/test.jpg")
> inputStream = FileInputStream.new(inFile)
>
> length = inFile.length()
> buffer = Java::byte[length].new
>
> inputStream.read(buffer)
>
> table = HTable.new(@hbase.configuration, "emails")
> p = Put.new(*jbytes("roger3.pdf"))
>
> p.add(*jbytes("inhalt", "", buffer))
>
> table.put(p)
>
> inputStream.close()
> table.close()
>
>
>
> Has anyone done this right?
>
> I tried and googled....no breakthrough :-/
>
> Thanks
> Roger
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message