【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';
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值