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!
解决方案
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: