hive加载数据
来源:互联网 发布:中金公司 知乎 编辑:程序博客网 时间:2024/06/08 05:40
创建表时加载
create table newtable as select col1,col2 from oldtable;
创建表时指定数据位置
create table tablename() location ''root@ubuntu:~# cat student1.txt xiaoming 10xiaohong 12xiaoli 13xiaowang 11root@ubuntu:~# hadoop fs -mkdir /user/hive/warehouse/dataroot@ubuntu:~# hadoop fs -put student1.txt /user/hive/warehouse/data/hive> create table student2(name string,age int) row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile location '/user/hive/warehouse/data/';OKTime taken: 0.272 secondshive> select * from student2;OKxiaoming 10xiaohong 12xiaoli 13xiaowang 11Time taken: 0.45 seconds, Fetched: 4 row(s)
本地数据加载
load data local inpath 'localpath' [pverwrite] into table tablename;root@ubuntu:~# cat student2.txt lucy 21lily 22hive> load data local inpath '/root/student2.txt' into table student2;Copying data from file:/root/student2.txtCopying file: file:/root/student2.txtLoading data to table default.student2[Warning] could not update stats.OKTime taken: 2.43 secondshive> select * from student2;OKxiaoming 10xiaohong 12xiaoli 13xiaowang 11lucy 21lily 22Time taken: 0.066 seconds, Fetched: 6 row(s)
加载hdfs数据
load data inpath 'hdfspath' [overwrite] into table tablename;(移动数据)
分区表数据加载
本地数据加载
load data local inpath 'localpath' [pverwrite] into table tablename partition(pn='');
加载hdfs数据
load data inpath 'hdfspath' [overwrite] into table tablename partition(pn='');
由查询语句加载数据
insert [overwrite|into] table tablename partition(pn='') select col1,col2 from table where ....
分区表数据加载
root@ubuntu:~# cat student1.txt xiaoming 10xiaohong 12xiaoli 13xiaowang 11hive> load data local inpath '/root/student1.txt' into table partitionTable partition(dt='20160818');Copying data from file:/root/student1.txtCopying file: file:/root/student1.txtLoading data to table default.partitiontable partition (dt=20160818)Partition default.partitiontable{dt=20160818} stats: [numFiles=1, numRows=0, totalSize=46, rawDataSize=0][Warning] could not update stats.OKTime taken: 1.831 secondshive> select * from partitionTable;OKxiaoming 10 20160818xiaohong 12 20160818xiaoli 13 20160818xiaowang 11 20160818Time taken: 0.354 seconds, Fetched: 4 row(s)hive> show partitions partitionTable;OKdt=20160818Time taken: 4.091 seconds, Fetched: 1 row(s)
外部分区表加载别忘了
alter table tablename add partition(dt='xxxx');
hive数据加载注意事项
分隔符,单个字符,写多个的话只取第一个
数据类型对应问题
load数据, 字段类型不能相互转化是,查询返回null
select查询插入,字段类型不能互相转化时,插入数据为null
root@ubuntu:~# cat test.txt lucy#hellojack#rose13#3545 hive> create table testType(name int,age string) row format delimited fields terminated by '#' lines terminated by '\n' stored as textfile;OKTime taken: 2.088 secondshive> load data local inpath '/root/test.txt' into table testType;hive> select * from testType;OKNULL helloNULL rose13 3545 Time taken: 0.035 seconds, Fetched: 3 row(s)root@ubuntu:~# hadoop fs -cat /user/hive/warehouse/testtype/test.txtlucy#hellojack#rose13#3545
select查询插入数据,字段值顺序要与表中字段顺序一致,名称可不一致,hive在加载数据时不做检查,查询是检查
外部分区表需要添加分区才能看到数据
0 0
- hive数据加载
- hive加载数据
- (7-11)hive加载数据
- Hive建表、加载数据模板
- Hive数据加载与保存
- Hive使用脚本加载数据
- Hive 建表 加载数据 查询
- hive加载数据和导出数据
- Hive SQL使用和数据加载
- hive 表创建及数据加载
- Hive的数据导入导出,插入,加载
- Hive使用记录-建表、加载数据
- Hive中数据的加载和导出
- 加载数据到hive中的方式
- hive 表数据加载、表删除试验
- 数据文件数据加载到hive表
- hive表加载数据的不同方式
- Hive 表数据 加载 、导出 、查询
- Smith Numbers
- 状态模式
- HDU 5860 Death Sequence(递推)
- 查询python已导入的modules 以及 如何取消已导入的modues
- LightOJ - 1138 Trailing Zeroes (III)
- hive加载数据
- JVM Attach机制实现
- vijos1037搭建双塔(一维背包问题)
- 1026. 程序运行时间(15)
- web前端开发遇到问题记录
- 基于Yahoo网站性能优化的34条军规及自己的见解
- Sunshine’s city(lct+线段树)
- Triangle leetcode
- PHP爬取百度图片