Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hbase shell - how to write byte value

Tags:

hbase

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.

like image 529
sethi Avatar asked Mar 27 '14 08:03

sethi


2 Answers

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

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

like image 84
Nanda Avatar answered Oct 19 '22 09:10

Nanda


you can also use Hbase built in functions like this

> put 'table','rowkey','cf:qua', Bytes.toBytes(1234)

it works for me.

like image 25
linehrr Avatar answered Oct 19 '22 09:10

linehrr