1,语法
CREATE EXTERNAL TABLE hive 表明 (hive字段名称1
数据类型, hive字段名称2
数据类型)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ( 和 hive 字段名称1 对应的 hbase 的列名
,和 hive 字段名称2 对应的 hbase 的列名
)
TBLPROPERTIES("hbase.table.name" = "hbase 的表明");
当需要映射hbase的key 的时候参考下面的方式
CREATE EXTERNAL TABLE hive 表明 (hive字段名称1(需要映射hbase的可以)
数据类型, hive字段名称2
数据类型)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ( 'hbase.columns.mapping'=":key,和 hive 字段名称2 对应的 hbase 的列名
)
TBLPROPERTIES("hbase.table.name" = "hbase 的表明");
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");