Hbase包含key映射爲hive表

1,語法apache

CREATE EXTERNAL TABLE hive 代表 (hive字段名稱1 數據類型, hive字段名稱2 數據類型)app

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

WITH SERDEPROPERTIES ( 和 hive 字段名稱1 對應的 hbase 的列名 ,和 hive 字段名稱2 對應的 hbase 的列名)code

TBLPROPERTIES("hbase.table.name" = "hbase 的代表");hadoop

當須要映射hbase的key 的時候參考下面的方式string

CREATE EXTERNAL TABLE hive 代表 (hive字段名稱1(須要映射hbase的能夠) 數據類型, hive字段名稱2 數據類型)table

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

WITH SERDEPROPERTIES ( 'hbase.columns.mapping'=":key,和 hive 字段名稱2 對應的 hbase 的列名)date

TBLPROPERTIES("hbase.table.name" = "hbase 的代表");map

eg:

CREATE EXTERNAL TABLE dim_sys_date(
`date_key` string , 
`date_seed` date ,
`day_of_week` int,
`day_of_week_desc` string,
`day_of_month` int,
`day_of_year` int ,
`is_last_day_of_month` int ,
`week_of_year` int,
`week_of_year_desc` string,
`year_week` int,
`first_day_of_week` date,
`last_day_of_week` date,
`month` int,
`month_desc` string,
`year_month` int,
`quarter` int,
`quarter_desc` string,
`year_quarter` string,
`year` string,
`is_weekend` string
) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' 
WITH SERDEPROPERTIES ( 
'hbase.columns.mapping'=":key,
calendar:dateSeed,
calendar:dayOfWeek,
calendar:dayOfWeekDesc,
calendar:dayOfMonth,
calendar:dayOfYear,
calendar:isLastDayOfMonth,
calendar:weekOfYear,
calendar:weekOfYearDesc,
calendar:yearAndWeek,
calendar:firstDayOfWeek,
calendar:lastDayOfWeek,
calendar:month,
calendar:monthDesc,
calendar:yearAndMonth,
calendar:quarter,
calendar:quarterOfDesc,
calendar:yearAndQuarter,
calendar:year,
calendar:isWeekend
"
) 
TBLPROPERTIES("hbase.table.name" = "dim_sys_date");
相關文章
相關標籤/搜索