当前位置:   article > 正文

Hive映射Hbase表的几种方式_hive外表hbase的字段映射简化

hive外表hbase的字段映射简化

1.Hive内部表,语句如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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外部表,语句如下,

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

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的列族

  1. CREATE EXTERNAL TABLE hiveFromHbase(
  2. rowkey string,
  3. f1 map<STRING,STRING>,
  4. f2 map<STRING,STRING>,
  5. f3 map<STRING,STRING>
  6. ) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
  7. WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,f1:,f2:,f3:")
  8. TBLPROPERTIES ("hbase.table.name" = "hbase_test");
  1. hive> select * from hiveFromHbase;
  2. OK
  3. r1 {"name":"zhangsan"} {"age":"20"} {"sex":"male"}
  4. r2 {"name":"lisi"} {"age":"30"} {"sex":"female"}
  5. r3 {"name":"wangwu"} {"age":"40"} {"sex":"male"}
  6. Time taken: 0.158 seconds, Fetched: 3 row(s)

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/78943
推荐阅读
相关标签
  

闽ICP备14008679号