Created
November 6, 2010 05:11
-
-
Save jmorton/665215 to your computer and use it in GitHub Desktop.
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
# Playing with Thrift, Hbase, and Ruby (I created a table and added some values using Hbase shell earlier) | |
irb > transport = Thrift::BufferedTransport.new(Thrift::Socket.new('localhost',9090)) | |
=> #<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=nil, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf=""> | |
irb > transport.open | |
=> #<Socket:0x10196a030> | |
irb > protocol = Thrift::BinaryProtocol.new(transport) | |
=> #<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=#<Socket:0x10196a030>, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">, @strict_write=true> | |
irb > client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol) | |
=> #<Apache::Hadoop::Hbase::Thrift::Hbase::Client:0x10195d448 @seqid=0, @oprot=#<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=#<Socket:0x10196a030>, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">, @strict_write=true>, @iprot=#<Thrift::BinaryProtocol:0x101964c98 @strict_read=true, @trans=#<Thrift::BufferedTransport:0x10196c678 @transport=#<Thrift::Socket:0x10196c6a0 @timeout=nil, @port=9090, @handle=#<Socket:0x10196a030>, @host="localhost", @desc="localhost:9090">, @index=0, @rbuf="", @wbuf="">, @strict_write=true>> | |
# Let's put it to use... | |
irb > client.getTableNames | |
=> ["people"] | |
irb > client.getColumnDescriptors("people") | |
=> {"locations"=><Apache::Hadoop::Hbase::Thrift::ColumnDescriptor name:6c6f636174696f6e73, maxVersions:3, compression:"NONE", inMemory:false, bloomFilterType:"false", bloomFilterVectorSize:0, bloomFilterNbHashes:0, blockCacheEnabled:true, timeToLive:-1>, "vitals"=><Apache::Hadoop::Hbase::Thrift::ColumnDescriptor name:766974616c73, maxVersions:3, compression:"NONE", inMemory:false, bloomFilterType:"false", bloomFilterVectorSize:0, bloomFilterNbHashes:0, blockCacheEnabled:true, timeToLive:-1>} | |
# Let's look at some data... | |
irb > row = client.getRow 'people', '1' | |
=> [<Apache::Hadoop::Hbase::Thrift::TRowResult row:31, columns:{766974616c733a6c6173744e616d65: <Apache::Hadoop::Hbase::Thrift::TCell value:4d6f72746f6e, timestamp:1289017113606>, 766974616c733a6d6964646c654e616d65: <Apache::Hadoop::Hbase::Thrift::TCell value:526f62657274, timestamp:1289017271077>, 766974616c733a66697273744e616d65: <Apache::Hadoop::Hbase::Thrift::TCell value:4a6f6e, timestamp:1289017099631>}>] | |
row.first.columns.map { |cf, cell| [cf, cell.value] } | |
=> [["vitals:lastName", "Morton"], ["vitals:middleName", "Robert"], ["vitals:firstName", "Jon"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment