Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Hive external tables to import HBase

Shulou Source: shulou.com Published: 2022-06-01 03:06:01 09月28日 Update

This article will explain in detail how to use Hive external tables to import HBase, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

Hive External Table

Create hbase table

(1)Create a table classes with 1 column family user

create 'classes','user'

(2)View table construction

hbase(main):005:0> describe 'classes'DESCRIPTION ENABLED 'classes', {NAME => 'user', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', true VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => ' false', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

(3)Add 2 lines of data

put 'classes','001','user:name','jack'put 'classes','001','user:age','20'put 'classes','002','user:name','liza'put 'classes','002','user:age','18'

(4)View data in classes

hbase(main):016:0> scan 'classes'ROW COLUMN+CELL 001 column=user:age, timestamp=1404980824151, value=20 001 column=user:name, timestamp=1404980772073, value=jack 002 column=user:age, timestamp=1404980963764, value=18 002 column=user:name, timestamp=1404980953897, value=liza

(5)Create external hive tables, query validation

create external table classes(id int, name string, age int) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,user:name,user:age") TBLPROPERTIES("hbase.table.name" = "classes");select * from classes;OK1 jack 202 liza 18

(6) Adding data to HBase

put 'classes','003','user:age','1820183291839132'hbase(main):025:0> scan 'classes'ROW COLUMN+CELL 001 column=user:age, timestamp=1404980824151, value=20 001 column=user:name, timestamp=1404980772073, value=jack 002 column=user:age, timestamp=1404980963764, value=18 002 column=user:name, timestamp=1404980953897, value=liza 003 column=user:age, timestamp=1404981476497, value=1820183291839132

(7) Hive queries to see new data

select * from classes;OK1 jack 202 liza 183 NULL NULL - -null here, because 003 has no name, so fill null, and age null because it exceeds the maximum value

(8) As proof,

put 'classes',' 004','user: name',' test 'put' classes','004',' user: age','1820183291839112312'--already exceeded int hbase (main): 030:0> scan 'classes' ROW COLUMN + CELL 001 column = user: age, timestamp = 1404980824151, value = 20 001 column = user: name, timestamp = 1404980772073, value = jack 002 column = user: age, timestamp = 1404980963764, value = 18 002 column = user: name, timestamp = 1404980953897, value = liza 003 column = user: age, timestamp = 1404981476497, value = 1820183291839132 004 column = user: age, timestamp = 1404981558125, value = 1820183291839112312 004 column = user: name, timestamp = 1404981551508, value = test select * from classes;1 jack 202 liza 183 NULL NULL4 test NULL nullput 'classes',' 005','user: age',' 1231342 'hbase (main): 034:0 * scan' classes 'ROW COLUMN + CELL 001 column = user: age, timestamp = 1404980824151, value = 20 001 column = user: name, timestamp = 1404980772073, value = jack 002 column = user: age, timestamp = 1404980963764, value = 18 002 column = user: name, timestamp = 1404980953897, value = liza 003 column = user: age, timestamp = 1404981476497, value = 1820183291839132 004 column = user: age, timestamp = 1404981558125, value = 1820183291839112312 004 column = user: name, timestamp = 1404981551508, value = test 005 column = user: age, timestamp = 1404981720600, value = 1231342 select * from classes; 1 jack 202 liza 183 NULL 4 test NULL 5 NULL 1231342 About "How to use Hive external table import HBase" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Data articles more query validation good practical maximum content articles maximum knowledge tables references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi Huawei vpn Apple