简体   繁体   English

如何从Hive读取HBase当前和先前版本的数据

[英]How to read hbase current and previous versions data from Hive

I want to read all the data from hbase table using Hive. 我想使用Hive从hbase表中读取所有数据。 Should be able to read all the Current and previous versions data from hbase 应该能够从hbase读取所有当前和先前版本的数据

You can specify the number of version you get for Scan and Get and it will retrieve them: 您可以指定要获取的“扫描”和“获取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 : Versioning is by default disabled while creating table. Note :默认情况下,在创建表时禁用版本控制。 So, you need to enable it. 因此,您需要启用它。

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}

For Hbase-hive integration follow the ref. 对于Hbase-hive集成,请遵循ref。 link : https://cwiki.apache.org/confluence/display/Hive/HBaseIntegration 链接: https : //cwiki.apache.org/confluence/display/Hive/HBaseIntegration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM