如何从 Hive 中读取 hbase 当前和以前的版本数据

How to read hbase current and previous versions data from Hive

我想使用 Hive 从 hbase table 读取所有数据。 应该能够从 hbase

读取所有当前和以前版本的数据

您可以指定为扫描和获取获取的 number of version,它将检索它们:

HTable cTable = new HTable(TableName);
Get res = new Get(Bytes.toBytes(key));

//set no. of version that you want to fetch.
res.setMaxVersions(verNo);  <--

Result fetchRow = cTable.get(res);
NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long,byte[] >>> allVersions = fetchRow.getMap();

Note:创建 table 时默认禁用版本控制。 所以,你需要启用它。

create 'employee',{NAME=>"myname",Versions=>2},'office' //Here versioning is enabled for column "myname" as "2" and no versioning for column "office"

describe 'employee'                                    // show you versioning information.

alter 'employee',NAME=>'office',VERSIONS =>4           // Alter

// Put and scan the table - it will show new and old value
put 'employee','1','myname:name','Jigyasa1'
put 'employee','1','myname:name','Jigyasa2'
put 'employee','1','office:name','Add1'
put 'employee','1','office:name','Add2'

scan 'employee',{VERSIONS=>10}

对于 Hbase-hive 集成,请遵循参考。 link : https://cwiki.apache.org/confluence/display/Hive/HBaseIntegration