Created
March 14, 2011 18:46
-
-
Save celeduc/869633 to your computer and use it in GitHub Desktop.
Using JRuby, put data into HBase and pull it back out, using HBase 0.20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export JRUBY_CLASSPATH="/usr/share/maven-repo/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:/usr/share/maven-repo/log4j/log4j/1.2.15/log4j-1.2.15.jar" | |
export HADOOP_CLASSPATH="/src/taproot/server/lib/InvPocTransform.jar:/usr/lib/hadoop-0.20/hadoop-core.jar:/usr/lib/hbase/hbase.jar:/usr/lib/hbase/lib/zookeeper.jar:/usr/lib/hbase/lib/guava-r05.jar:$HADOOP_CLASSPATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
include Java | |
require 'java' | |
ENV["HADOOP_CLASSPATH"].split(":").each {|jar| require jar} | |
ENV["JRUBY_CLASSPATH"].split(":").each {|jar| require jar} | |
include_class Java::org.apache.hadoop.hbase.HBaseConfiguration | |
include_class Java::org.apache.hadoop.hbase.client.Get | |
include_class Java::org.apache.hadoop.hbase.client.HTable | |
include_class Java::org.apache.hadoop.hbase.client.Put | |
include_class Java::org.apache.hadoop.hbase.client.Result | |
def jbytes( str ) | |
str.to_java_bytes | |
end | |
# Configuration | |
conf = HBaseConfiguration.new | |
table = HTable.new(conf, "data") | |
row = jbytes("row_x") | |
p = Put.new(row) | |
p.add(jbytes("raw"), jbytes("csv"), jbytes("1,1,1,1")) | |
table.put(p) | |
# Now fetch it back. | |
g = Get.new(row) | |
res = table.get(g) | |
data = res.getValue(jbytes("raw"), jbytes("csv")) | |
data_s = String.from_java_bytes data | |
print "The fetched row contains the value '#{data_s}'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can some one let me know how to execute jruby-hbase-round-trip.rb, what i am trying is as mention below:-
./environment.sh (I have added one more jar to Classpath - jruby-complete-1.1.1.jar )
jruby -S jrubyc jruby-hbase-round-trip.rb
The above commands gives below error:-
java org.jruby.Main jruby-hbase-round-trip
Error opening script file: /jruby-hbase-round-trip (No such file or directory)
any pointers??