Hive查询指定分隔符
业务场景:
做数据分析的时候,经常会用到hive -e "sql" > result.csv,然后将结果导入到excel中,可是使用hive -e
导出后默认的分隔符是\t
,excel无法识别,所以需要将\t
转成,
方案一:使用linux管道符替换
hive -e "select * from table_name limit 100" | sed 's/\t/,/g' > result.csv
或者
hive -e "select * from table_name limit 100" | tr "\t" "," > result.csv
方案二:使用hive的insert语法导出文件
insert overwrite local directory '/home/hadoop/20180303' row format delimited fields terminated by ',' select * from table_name limit 100

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Hive之行转列/列转行
1、行转列 场景:在hive表中,一个用户会有多个人群标签,List格式(逗号分隔如要转成List),有时我们需要统计一个人群标签下有少用户,这是就需要使用行转列了 例如,user_crowd_info有如下数据 visit_id crowds abc [100,101,102] def [100,101] abe [101,105] 可以使用的函数 select explode(crowds) as crowd from user_crowd_info; 结果: 100 101 102 100 101 101 105 这样执行的结果只有crowd, 但是我们需要完整的信息,使用select visit_id, explode(crowds) as crowd from user_crowd_info;是不对的,会报错UDTF's are not supported outside the SELECT clause, nor nested in expressions 所以我们需要这样做: select visit_id,crowd from user_crowd_info t la...
- 下一篇
Hive进阶
hive配置,命令 hive查询显示列名 set hive.cli.print.header=true; // 打印列名 set hive.cli.print.row.to.vertical=true; // 开启行转列功能, 前提必须开启打印列名功能 set hive.cli.print.row.to.vertical.num=1; // 设置每行显示的列数 hive默认分隔符 \001 hive命令行中查看当前hive环境变量 !env hive命令行中查看当前hive及hadoop环境变量 set -v hive分析结果导出到文件 insert overwrite local directory '/tmp/output' select * from table_name; insert overwrite local directory '/tmp/output' row format delimited fields terminated by ',' select * from table_name hive import import中的这个参数不能和hive的地址一样,...
相关文章
文章评论
共有0条评论来说两句吧...