Hbase shell - how to write byte value

sethi picture sethi · Mar 27, 2014 · Viewed 8.4k times · Source

I want to write a value say 65 in hbase. I have to run the following command on hbase shell for that:

put 'table','key','cf:qual','A'

But is there a way to write it directly something like:

put 'table','key','cf:qual',65 (this is not allowed though)

Let me know if you understand the question else I will explain more.

Update:

By 65 I meant to put 'A' but directly the ascii value of 'A'. The real issue for me is I want to put values which fall in the range of 128-255 from the shell.

Answer

Nanda picture Nanda · Apr 11, 2014

Since Hbase Shell is implemented using ruby you can insert byte values by representing them in hexadecimal format.

For example if you want to insert a byte value 255:

hex representation of 255 is FF. In Hbase shell we should give it as stringBinary which is "\xFF"

The "\x" is a special escape character to encode an arbitrary byte from hex, so "\xFF" means byte 0xFF.

so put 'table', 'rowkey', 'cf:qual', "\xFF" will insert the byte 255

Important note: The value has to be with in " " (double quotes) not ' ' (single quotes).

Useful links:

How Does Ruby handle bytes/binary

Hexadecimal Digits (Hex-Codes) Cheatsheet