Java(HBase)API:如何知道以字节存储的值的数据类型 [英] Java(HBase) API: How to know the data type of a value stored in bytes

查看:1417
本文介绍了Java(HBase)API:如何知道以字节存储的值的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HBase Java API时,我有一行代码如下:

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

假设我不知道这是一个Int或String类型的值,应该在 Byte.toInt(value) Byte.toString(value)之间使用以正确打印值

这不是一个真正的HBase / Hadoop问题,而是一个Java问题,但我使用Google搜索并找不到获取它的方法。有可能知道吗?

从HBase Java API的另一个方向,我如何知道存储在family:qualifier中的给定值的数据类型?



感谢! t支持键入列,数据存储区跟踪所存储数据的类型。 HBase本身并没有跟踪 - 所以没有办法本地告诉 - 存储在列中的数据的类型。使用HBase的开发人员负责自行跟踪列数据类型。

对于许多应用程序,应用程序可以对这些类型进行硬编码的每列。通过这种方式,HBase表往往比RDBMS表更适用于特定应用程序。开发人员还可以为该行创建专用于数据类型模式的列族或列(例如,将Avro模式序列化为字符串)。



HBase文档体系结构页面解释了HBase和传统RDBMS在这里的差异:

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


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:

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

这篇关于Java(HBase)API:如何知道以字节存储的值的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆