HQL加载数据的几种方法小结
2016-09-25 10:35
471 查看
HQL加载数据的几种方法小结:
对于没有创建分区的表(这里都以外部表为例)而言:
create external table if not exists test
(id int,name string)
comment 'This is for test.'
row format delimited
fields terminated by '\t'
location '/in/test';
1.直接在linux中上传文件到hive表对应的location
hadoop fs -put ~/Desktop/11 hive创建表的路径
例如:hadoop fs -put linux文件的路径 /in/test
create external table if not exists test
(id int,name string)
comment 'This is for test.'
row format delimited
fields terminated by '\t';
2.在hive中加载数据
load data local inpath 'linux文件的路径'
overwrite into table hive的表名;
例如:load data local inpath '/home/yff/Desktop/11'
overwrite into table test;
需要注意:
a.执行语句中overwrite是重写,不加overwrite是追加操作。
b.创建hive表的时候没有指明表的location,所以文件默认存放在hdfs的/user/hive/warehouse路径对应的数据库下面,如果指明location,那么文件会加载到相应位置里
create external table if not exists test
(id int,name string)
comment 'This is for test.'
row format delimited
fields terminated by '\t';
3.在hive中直接加载已经存在的表的数据
insert overwrite table 表名 select语句fromhive已存在的表;
例如:insert overwrite table test select * from user;
需要注意:
a.该执行语句中的overwrite不能省略
4.创建新表的同时加载数据
create table 表名 as select语句fromhive已存在的表;
例如:create table test as select name,user_id from user;
需要注意:
a.不能创建外部表
对于创建静态分区的表而言:
create external table if not exists test
(name string,id int)
comment 'This is for test.'
partitioned by (date string)
row format delimited
fields terminated by '\t';
通过在hive中load data的方式加载数据:
load data local inpath 'linux本地文件路径'
overwrite into table 表名
partition(分区字段='分区字段值');
例如:load data local inpath '/home/yff/Desktop/11'
overwrite into table test
partition(date='2016-09-25');
对于创建动态分区的表而言:
create external table if not exists test
(name string,price double)
comment 'This is for test.'
partitioned by (date string)
row format delimited
fields terminated by '\t';
首先记得设置一下动态分区的属性:
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.dynamic.partitions.pernode=1000;
通过在hive中直接加载已经存在的表的数据:
insert overwrite table 表名 partition(分区字段...)
select 表本身字段..., 分区字段... fromhive已存在的表;
例如:insert overwrite table test partition(date)
select name,price,time from product;
对于没有创建分区的表(这里都以外部表为例)而言:
create external table if not exists test
(id int,name string)
comment 'This is for test.'
row format delimited
fields terminated by '\t'
location '/in/test';
1.直接在linux中上传文件到hive表对应的location
hadoop fs -put ~/Desktop/11 hive创建表的路径
例如:hadoop fs -put linux文件的路径 /in/test
create external table if not exists test
(id int,name string)
comment 'This is for test.'
row format delimited
fields terminated by '\t';
2.在hive中加载数据
load data local inpath 'linux文件的路径'
overwrite into table hive的表名;
例如:load data local inpath '/home/yff/Desktop/11'
overwrite into table test;
需要注意:
a.执行语句中overwrite是重写,不加overwrite是追加操作。
b.创建hive表的时候没有指明表的location,所以文件默认存放在hdfs的/user/hive/warehouse路径对应的数据库下面,如果指明location,那么文件会加载到相应位置里
create external table if not exists test
(id int,name string)
comment 'This is for test.'
row format delimited
fields terminated by '\t';
3.在hive中直接加载已经存在的表的数据
insert overwrite table 表名 select语句fromhive已存在的表;
例如:insert overwrite table test select * from user;
需要注意:
a.该执行语句中的overwrite不能省略
4.创建新表的同时加载数据
create table 表名 as select语句fromhive已存在的表;
例如:create table test as select name,user_id from user;
需要注意:
a.不能创建外部表
对于创建静态分区的表而言:
create external table if not exists test
(name string,id int)
comment 'This is for test.'
partitioned by (date string)
row format delimited
fields terminated by '\t';
通过在hive中load data的方式加载数据:
load data local inpath 'linux本地文件路径'
overwrite into table 表名
partition(分区字段='分区字段值');
例如:load data local inpath '/home/yff/Desktop/11'
overwrite into table test
partition(date='2016-09-25');
对于创建动态分区的表而言:
create external table if not exists test
(name string,price double)
comment 'This is for test.'
partitioned by (date string)
row format delimited
fields terminated by '\t';
首先记得设置一下动态分区的属性:
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.dynamic.partitions.pernode=1000;
通过在hive中直接加载已经存在的表的数据:
insert overwrite table 表名 partition(分区字段...)
select 表本身字段..., 分区字段... fromhive已存在的表;
例如:insert overwrite table test partition(date)
select name,price,time from product;
相关文章推荐
- 遍历json获得数据的几种方法小结
- 加载地图数据的几种方法(AE + C#)
- 加载地图数据的几种方法
- oracle数据加载的几种常用方法
- SQLServer 数据导入导出的几种方法小结
- 加载地图数据的几种方法(AE + C#)
- js中对arry数组的各种操作小结 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据 web前端url传递值 js加密解密 HTML中让表单input等文本框为只读不可编辑的方法 js监听用户的键盘敲击事件,兼容各大主流浏览器 HTML特殊字符
- vue路由组件按需加载的几种方法小结
- Hibernate查询数据的几种方式以及HQL用法及参数的几种使用方法
- arcgis engine中几种常用数据的加载方法
- 让浏览器非阻塞加载javascript的几种方法小结
- 加载地图数据的几种方法(AE + C#)
- 让浏览器非阻塞加载javascript的几种方法小结
- XForms 表单预加载数据的几种方法
- SQLServer 数据导入导出的几种方法小结
- datagrid数据导出到excel文件给客户端下载的几种方法(转)
- 总结一下最近一段时间导出数据到Excel的几种方法
- datagrid数据导出到excel文件给客户端下载的几种方法
- Web程序中网页间数据传递方法小结
- 导出数据到Excel的几种方法