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!
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With