Skip to content

Instantly share code, notes, and snippets.

@haridsv
Last active June 22, 2019 10:17
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save haridsv/bf636b23c458033a9359 to your computer and use it in GitHub Desktop.
Decode byte strings from HBase shell, a collection of snippets
hbase(main):002:0> T = create 'emp',  {NAME => 'f', VERSIONS => 5}
0 row(s) in 1.1300 seconds

=> Hbase::Table - emp
hbase(main):003:0> T.put '001', 'f:name', 'Tom'
0 row(s) in 0.0890 seconds
hbase(main):003:0> T.put '001', 'f:name', 'Tom Too'
0 row(s) in 0.0890 seconds
hbase(main):004:0> T.get '001'
COLUMN                                                                CELL
 f:name                                                               timestamp=1438165671345, value=Tom Too
1 row(s) in 0.0120 seconds
hbase(main):005:0> T.get '001', {COLUMN => 'f:name', TIMERANGE => [0, 1438165671345]}
COLUMN                                                                CELL
 f:name                                                               timestamp=1438165659765, value=Tom
1 row(s) in 0.0140 seconds
hbase(main):006:0> T.get '001', {COLUMNS => 'f:name', VERSIONS => 5}
COLUMN                                                                CELL
 f:name                                                               timestamp=1438165671345, value=Tom Too
 f:name                                                               timestamp=1438165659765, value=Tom
2 row(s) in 0.0070 seconds
hbase(main):007:0> T.scan({COLUMNS=>['f:name'], VERSIONS => 5})
ROW                                                                   COLUMN+CELL
 001                                                                  column=f:name, timestamp=1438165671345, value=Tom Too
 001                                                                  column=f:name, timestamp=1438165659765, value=Tom
1 row(s) in 0.0320 seconds
hbase(main):003:0> T.put '002', 'f:name', 'Dick'
hbase(main):003:0> T.put '003', 'f:name', 'Harry'

Decode a long value (such as of time type) using Phoenix 4.4.x

hbase(main):007:0> import org.apache.phoenix.schema.types.PLong
=> Java::OrgApachePhoenixSchemaTypes::PLong
hbase(main):008:0> import org.apache.phoenix.schema.SortOrder
=> Java::OrgApachePhoenixSchema::SortOrder
hbase(main):009:0> PLong::INSTANCE.getCodec.decodeLong("\x80\x00\x01N\xA5`H\xA6".to_java_bytes, 0, SortOrder::ASC)
=> 1437293627558
hbase(main):010:0> PLong::INSTANCE.getCodec.decodeLong("\x80\x00\x01N\xA5`H\xA5".to_java_bytes, 0, SortOrder::ASC)
=> 1437293627557
hbase(main):011:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment