/////////////////建表//////////////////////////// create external table ods.dict_mobile_area( telphone_header string , province string, city string, province_code string, city_code string ) comment '手機區域表字典表' row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile location '/user/xdr/mobileArea'; ////////////////////數據插入//////////////////////////// Insert overwrite table app.draw_user_terminal_detail partition (month_par='201307') Select t1.mobile, t1.IMEI, t2.terminal_name, t3.province_code, t3.city_code, t3.province, t3.city, t1.update_time from ods.unicom_terminal_log t1 left OUTER join ods.dict_tac_band t2 on substring(t1.IMEI,0,8) = t2.tac left OUTER join ods.dict_mobile_area t3 on substring(t1.telphone,0,7) = t3.telphone_header /////替換原有列//////////////////////////// ALTER TABLE dict_mobile_area REPLACE COLUMNS ( mobile_header string , province string, city string, province_code string, city_code string ) // 建立表 create table app.draw_user_lac_ci_hour as select * from pdw.draw_user_lac_ci_log //修改表名稱 ALTER TABLE draw_user_lac_ci_log RENAME TO draw_user_lac_ci_hour //刪除表 刪除表: drop table if exists app.hbase_draw_user_internet_use_month; //hive hbase 整合 CREATE EXTERNAL TABLE app.hbase_draw_user_internet_use_month ( key string, imei string , terminal_name string, factory_name string, terminal_type string, is_smart string, province_code string, city_code string, province string, city string, month string ) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ( "hbase.columns.mapping" = ":key,colfam:imei, colfam:terminal_name, colfam:factory_name, colfam:terminal_type, colfam:is_smart, colfam:province_code, colfam:city_code, colfam:province, colfam:city, colfam:month") TBLPROPERTIES ("hbase.table.name" = "cdr_draw_user_internet_use_month"); create external table app.hbase_draw_user_internet_use_month(key string,colfam map<string,string>) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" =":key,colfam:") TBLPROPERTIES ("hbase.table.name" = "cdr_draw_user_internet_use_month"); create table app.hbase_cdr_draw_user_marketing_people_test(key string,colfam map<string,string>) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" =":key,colfam:") TBLPROPERTIES ("hbase.table.name" = "cdr_draw_user_marketing_people_test"); insert overwrite table app.hbase_cdr_draw_user_marketing_people_test SELECT key,colfam FROM app.hbase_draw_user_internet_use_month t where t.colfam['month']='201307' and t.colfam['province_code']='036' and t.colfam['city_code']='0360' and t.colfam['terminal_name']='iPhone 4' and t.colfam['label_set'] like '%手機郵件%微信達人%'