天天看點

【Hadoop】HIVE 資料表 使用

3 使用

3.1 資料導入

3.1.1 可以使用指令行導入,也可以直接上傳到HDFS的特定目錄

3.1.2 格式問題

3.1.2.1 缺失/不合法字段預設值為NULL

3.1.2.2 最好資料是格式化的,不要缺失字段

3.1.3 從HDFS其他目錄導入

3.1.3.1 hadoop fs -put order_ext.txt / load data inpath '/order_ext.txt' into table tbl_order;

3.1.3.2 自動移動資料到HDFS特定目錄

3.2 資料表類型

3.2.1 MANAGED

3.2.1.1 預設TABLE類型

3.2.1.2 DROP

3.2.1.2.1 資料删除,整個目錄删除

3.2.2 EXTERNAL

3.2.2.1 不要求資料放在特定目錄,不影響業務系統的持續運作

3.2.2.2 示例

3.2.2.2.1 hadoop fs -mkdir -p /hive_ext hadoop fs -put order_ext.txt /hive_ext //////////////////////////////////////////////////////////////////////////////////////////////////////// create external table tbl_order_ext(id int, name string, size string, price double) row format delimited fields terminated by '\t' location '/hive_ext';

3.2.2.3 EXTERNAL類型TABLE在HDFS上沒有建立特定目錄,在HIVE的TBLS表中可以查詢

3.2.2.4 DROP

3.2.2.4.1 隻删除邏輯表(中繼資料),資料不删除,不影響業務資料

3.2.3 臨時表

3.2.3.1 CREATE AS

3.2.3.1.1 參考

3.2.3.1.1.1 http://blog.chinaunix.net/uid-451-id-3125462.html

3.2.3.1.2 示例

3.2.3.1.2.1 create table tbl_order_ctas as select id,name,price from tbl_order; //////////////////////////////////////////////////////////////////////////////////////////////////////// select * from tbl_order_ctas;

3.2.3.2 INSERT INTO/OVERWRITE

3.2.3.2.1 參考

3.2.3.2.1.1 http://www.cnblogs.com/RoadGY/archive/2011/07/22/2114088.html

3.2.3.2.2 示例

3.2.3.2.2.1 insert into tbl_order_ctas select id,name,price from tbl_order_ext;

3.2.4 PARTITION

3.2.4.1 示例

3.2.4.1.1 create table tbl_order_pt(id int, name string, size string, price double) partitioned by (month string) row format delimited fields terminated by '\t'; //////////////////////////////////////////////////////////////////////////////////////////////////////// load data local inpath 'order_new.txt' into table tbl_order_pt partition(month='201601'); load data local inpath 'order_broken.txt' into table tbl_order_pt partition(month='201602'); //////////////////////////////////////////////////////////////////////////////////////////////////////// select * from tbl_order_pt where month='201602';

【Hadoop】HIVE 資料表 使用