Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java(HBase) API: How to know the data type of a value stored in bytes

Tags:

java

hbase

when working with HBase Java API, I have a line of the code as below:

byte[] value = scanner.next().getValue(Bytes.toBytes(family), Bytes.toBytes(qualifier));

Assume I don't know if it's a Int or String type for this value, which should I use between Byte.toInt(value) and Byte.toString(value) to print the value correctly?

This is not a really HBase/Hadoop question, and rather a Java one, but I googled and can't find a way to get it. Is it possible to know it?

In another direction, from the HBase Java API, how can I know the data type for a given value stored in a family:qualifier?

Thanks!

like image 252
leslie Avatar asked Jan 12 '12 11:01

leslie


People also ask

What is the data type of version in HBase?

There are no fancy data types such as String , INT , or Long in HBase; it's all byte array. It's a kind of byte-in and byte-out database, wherein, when a value is inserted, it is converted into a byte array using the Put and Result interfaces.


1 Answers

Unlike a traditional RDBMS, HBase doesn't support "typed columns", where the data store keeps track of the types of data being stored. HBase does not natively keep track of - so there is no way to natively tell - the type of data stored in a column. The developer using HBase is responsible for keep track of column data types on their own.

For many applications, it is acceptable for the application to "hard-code" the types of each column. In this way, HBase tables tend to be more application-specific than RDBMS tables. A developer can also create a column family or column dedicated to a data type schema for the row (for example, an Avro schema serialized as a string).

The HBase documentation's "Architecture" pages explains the differences between HBase and a traditional RDBMS a bit more here:

https://hbase.apache.org/book/architecture.html#arch.overview.when

like image 64
Chris Stephens Avatar answered Oct 16 '22 21:10

Chris Stephens