网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

Hive映射HBase表的方式有哪些

本篇内容主要讲解“Hive映射HBase表的方式有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Hive映射HBase表的方式有哪些”吧!

创新互联建站主营通辽网站建设的网络公司,主营网站建设方案,成都app开发,通辽h5微信小程序搭建,通辽网站营销推广欢迎通辽等地区企业咨询

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

2

3

4

5

6

7

CREATE                   TABLE                   hbase_table_1(value map         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

两种方式可以根据需求确定,详细参见官方文档。

到此,相信大家对“Hive映射HBase表的方式有哪些”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


分享文章:Hive映射HBase表的方式有哪些
地址分享:http://bjjierui.cn/article/gsigig.html

其他资讯