標籤:
hive綜合hbase兩個優勢表中的:
1.實現資料匯入到MYSQL。
2.實現hbase錶轉換為另外一張hbase表。
三個操作環節:
1.hbase關聯hive作為外部表格:
Sql代碼
- CREATE EXTERNAL TABLE hive_device_app(row_key string,genera_type string,install_type string,label string,meid string,model string,pkg_name string,specific_type string)
- STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘
- WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:genera_type,cf:install_type,cf:label,cf:meid,cf:model,cf:pkg_name,cf:specific_type")
- TBLPROPERTIES("hbase.table.name" = "tb_yl_device_app_info1");
2.hbase真正關聯hive,hive的插入更新等操作直接影響hbase中的資料
Sql代碼
- CREATE TABLE hbase_device_app(row_key string,genera_type string,install_type string,label string,meid string,model string,pkg_name string,specific_type string)
- STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘
- WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:genera_type,cf:install_type,cf:label,cf:meid,cf:model,cf:pkg_name,cf:specific_type")
- TBLPROPERTIES("hbase.table.name" = "tb_yl_device_app_info2");
3.建立一張hive表
Sql代碼
- CREATE TABLE hive_device_app_real(row_key string,genera_type string,install_type string,label string,meid string,model string,pkg_name string,specific_type string)
4.外部表格資料匯入hive實表
Sql代碼
- insert overwrite table hive_device_app_real select * from hive_device_app
5.sqoop匯出hive的資料到mysql
Sql代碼
- sqoop export --connect jdbc:mysql://Hadoop48/toplists -m 1 --table hive_device_app_real --export-dir /user/hive/warehouse/hive_device_app_real/000000_0 --input-null-string "\\\\N" --input-null-non-string "\\\\N" --input-fields-terminated-by "\\01" --input-lines-terminated-by "\\n"
6.habse(關聯hive)中一張錶轉到另外一張表當然能夠利用hive的內建函數實現資料處理
Sql代碼
- insert overwrite table another_hive_hbase_related_table select * from hbase_device_app
匯出hbase中資料到mysql須要經過步驟:1345
hbase在一個表到另一個表(中間可以使用hive用於資料處理的內建函數):226
hbase結合hive和sqoop實現資料指導mysql