hive相关命令总结

hive导出数据

hive -e “sql语句” > 路径

这个方法最为常见,sql的查询结果将直接保存到/home/output/out.txt中

hive -e "select user, login_timestamp from user_login" > /home/output/out.txt

当sql脚本过多时,也可以使用 -f sql文件名 ,按下面的方式执行查询,并保存结果

hive -f file.sql > /home/hadoop/output/cai/out.txt

导出csv文件

hive导出数据默认分隔符为"\t",需要转换成","
在执行语句后加入 | tr "\t" ","

hive -e "select * from table "  | tr "\t" ","> /home/output/out.csv

有些文件包含中文在导出csv后可能回出现乱码情况

导出数据包含标题

增加:set hive.cli.print.header=true;

hive -e "set hive.cli.print.header=true; select user, login_timestamp from user_login" > /home/output/out.txt

hive报错

sql没错但是任务失败

可能原因是被更高资源的任务抢占了,导致失败次数超过设定的失败次数,进而报错。尝试通过下面代码解决。

set hive.vectorized.execution.enabled=false;

设置非严格模式

  • 分区
  • 排序limit
  • 可以产生笛卡尔积
set hive.mapred.mode = strict;
set hive.mapred.mode = nonstrict;

hive展示

表的字段名显示

set hive.cli.print.header=true;

显示数据库名称

set hive.cli.print.current.db=true;

hive url解码

select reflect("java.net.URLDecoder", "decode", "%E4%B8%AD%E5%9B%BD", "UTF-8");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值