sethi
sethi

Reputation: 1889

Hbase shell - how to write byte value

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.

Upvotes: 12

Views: 10514

Answers (2)

Nanda
Nanda

Reputation: 985

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

Upvotes: 22

linehrr
linehrr

Reputation: 1748

you can also use Hbase built in functions like this

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

it works for me.

Upvotes: 7

Related Questions