文章出處

1.Hive內部表,語句如下

CREATE TABLE ods.s01_buyer_calllogs_info_ts(
key string comment "hbase rowkey",
buyer_mobile string comment "手機號",
contact_mobile string comment "對方手機號",
call_date string comment "發生時間",
call_type string comment "通話類型",
init_type string comment "0-被叫,1-主叫",
other_cell_phone string comment "對方手機號",
place string comment "呼叫發生地",
start_time string comment "發生時間",
subtotal string comment "通話費用",
use_time string comment "通話時間(秒)"
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'     
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,record:buyer_mobile,record:contact_mobile,record:call_date,record:call_type,record:init_type,record:other_cell_phone,record:place,record:start_time,record:subtotal,record:use_time")     
TBLPROPERTIES("hbase.table.name" = "s01_buyer_calllogs_info_ts");

   建好表之后,進入hbase shell執行list能看到表s01_buyer_calllogs_info_ts,hive drop掉此表時,hbase也被drop。

2.Hive外部表,語句如下,

create 'buyer_calllogs_info_ts', 'record', {SPLITS_FILE => 'hbase_calllogs_splits.txt'}

CREATE EXTERNAL TABLE ods.s10_buyer_calllogs_info_ts(
key string comment "hbase rowkey",
buyer_mobile string comment "手機號",
contact_mobile string comment "對方手機號",
call_date string comment "發生時間",
call_type string comment "通話類型",
init_type string comment "0-被叫,1-主叫",
other_cell_phone string comment "對方手機號",
place string comment "呼叫發生地",
start_time string comment "發生時間",
subtotal string comment "通話費用",
use_time string comment "通話時間(秒)"
)     
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'     
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,record:buyer_mobile,record:contact_mobile,record:call_date,record:call_type,record:init_type,record:other_cell_phone,record:place,record:start_time,record:subtotal,record:use_time")     
TBLPROPERTIES("hbase.table.name" = "buyer_calllogs_info_ts");

   從方式需要先在hbase建好表,然后在hive中建表,hive drop掉表,hbase表不會變。

3.Hive映射HBase的列族

CREATE TABLE hbase_table_1(value map<string,int>, row_key int) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES (
"hbase.columns.mapping" = "cf:,:key"
);
INSERT OVERWRITE TABLE hbase_table_1 SELECT map(bar, foo), foo FROM pokes 
WHERE foo=98 OR foo=100;

  在hbase查看結果

hbase(main):012:0> scan "hbase_table_1"
ROW                          COLUMN+CELL                                                                      
 100                         column=cf:val_100, timestamp=1267739509194, value=100                            
 98                          column=cf:val_98, timestamp=1267739509194, value=98                              
2 row(s) in 0.0080 seconds
在hive查看結果
hive> select * from hbase_table_1;
Total MapReduce jobs = 1
Launching Job 1 out of 1
...
OK
{"val_100":100}	100
{"val_98":98}	98
Time taken: 3.808 seconds

兩種方式可以根據需求確定,詳細參見官方文檔

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()