Hbase、Hive、Impala資料同步簡單示例

一塵在心發表於2018-08-20

Hbase +hive+impala資料同步簡單示例

首先先在hbase建立表

hbase

hbase shell

list

scan 'TEST_INFO'

create 'TEST_INFO','d'

put ‘TEST_INFO’,’001’,’fields’,’VALUE’,

scan 'TEST_INFO'

Hive

hive建立外部表

 

show databases;

show tables;

CREATE EXTERNAL TABLE TEST_INFO(

 id string,field12 string,field13 string,field14 string, field15 string,field16 string, field17 string, field18 string, field19 string,field20 string,field21 string,field22 string,field23 string,field24 string,field25 string, field26 string,field27 string,field28 string, field29 string,field30 string, field31 string, field32 string,field33 string,field34 string,field35 string)

ROW FORMAT SERDE 'org.apache.hadoop.hive.hbase.HBaseSerDe'

STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'

WITH SERDEPROPERTIES ('serialization.format'='\t','hbase.columns.mapping'=':key, d:field12,d:field13,d:field14, d:field15, d:field16,d:field17, d:field18,d:field19, d:field20,d:field21, d:field22,d:field23, d:field24,d:field25, d:field26,d:field27, d:field28,d:field29, d:field30,d:field31, d:field32,d:field33, d:field34, d:field35','field.delim'='\t')

TBLPROPERTIES('hbase.table.name'='TEST_INFO');

 

hive> CREATE EXTERNAL TABLE TEST_INFO(

    >  id string,field12 string,field13 string,field14 string, field15 string,field16 string, field17 string, field18 string, field19 string,field20 string,field21 string,field22 string,field23 string,field24 string,field25 string, field26 string,field27 string,field28 string, field29 string,field30 string, field31 string, field32 string,field33 string,field34 string,field35 string)

    > ROW FORMAT SERDE 'org.apache.hadoop.hive.hbase.HBaseSerDe'

    > STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'

    > WITH SERDEPROPERTIES ('serialization.format'='\t','hbase.columns.mapping'=':key, d:field12,d:field13,d:field14, d:field15, d:field16,d:field17, d:field18,d:field19, d:field20,d:field21, d:field22,d:field23, d:field24,d:field25, d:field26,d:field27, d:field28,d:field29, d:field30,d:field31, d:field32,d:field33, d:field34, d:field35','field.delim'='\t')

    > TBLPROPERTIES('hbase.table.name'='TEST_INFO');

hive> desc test_info;

hive>select * from test_info;

impala

impala-shell

#同步hive 到ipmala

INVALIDATE METADATA; 

[cdh002:21000] > desc test_info;

 #檢視到對映HBase中表的結構:

[cdh002:21000] > select * from test_info;

相關文章