温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HQL操作日常使用命令总结

发布时间:2020-07-19 13:00:48 来源:网络 阅读:431 作者:CARYFLASH 栏目:大数据

建表

create table mydb.userinfo(name string,addressi string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS TEXTFILE;

创建分区表

CREATE TABLE mydb.userinfo    --创建表
(col1 string, col2 date, col3 double), 
partitioned by (datekey date),  --可以多个字段的组合分区 
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ',' 
Stored AS TEXTFILE;

数据导入到表mydb.userinfo中

load data local inpath "/home/dahaizi/data/userinfo.txt" 
overwrite into table mydb.userinfo;

向表中插入数据

insert into table(col1,col2,col3) values('a','b','c')

将查询的数据插入到已有的表中

INSERT INTO TABLE table_Name
PARTITION (DateKey),
SELECT col1,col2,col3,DateKey FROM otherTable
WHERE DATEKEY IN ('2017-02-26','2013-06-12','2013-09-24'),
GROUP BY col1,col2,col3,DateKey
DISTRIBUTE BY DateKey

将查询的数据存储的hdfs目录中

insert overwrite directory '/jc_bdcqs/qsy'
row format delimited
fields terminated by ','
select * from zqs_gs_g60_0730_list;
!quit

HQL查询常用设置项

1)设置计算容错率(防止因计算过程出错而异常退出程序):
set mapred.max.map.failures.percent=100;
2)限制查询输出文件的个数
set mapred.reduce.tasks=1;
3) 控制最大reduce的数量,不会影响mapred.reduce.tasks的设置
set hive.exec.reducers.max = 100;
4) 一个job会有多少个reducer来处理,默认为1G
set hive.exec.reducers.bytes.per.reducer = 1000000000;

设置动态分区

set hive.exec.dynamic.partition=true;(可通过这个语句查看:set hive.exec.dynamic.partition;), 
set hive.exec.dynamic.partition.mode=nonstrict; 
SET hive.exec.max.dynamic.partitions=100000;(如果自动分区数大于这个参数,将会报错),
SET hive.exec.max.dynamic.partitions.pernode=100000;

删除表

drop table tb_name;
或清空表
truncate table table_name;

删除分区

ALTER TABLE table_Name DROP PARTITION (Datekey='20190606');

新增分区

alter table tb_name add partition (Datekey = ‘20190606’);

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI