如何将 Hive 表导出为 CSV 文件? [英] How to export a Hive table into a CSV file?

查看:159
本文介绍了如何将 Hive 表导出为 CSV 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此 Hive 查询将表导出为 CSV 文件.

I used this Hive query to export a table into a CSV file.

INSERT OVERWRITE DIRECTORY '/user/data/output/test' select column1, column2 from table1;

生成的000000_0"文件没有逗号分隔符

The file generated '000000_0' does not have comma separator

这是生成 CSV 文件的正确方法吗?如果没有,请告诉我如何生成 CSV 文件?

Is this the right way to generate CSV file? If no, please let me know how can I generate the CSV file?

推荐答案

或使用这个

hive -e 'select * from your_Table' | sed 's/[	]/,/g'  > /home/yourfile.csv

您还可以在 SELECT 之前指定属性 set hive.cli.print.header=true 以确保创建标头和数据并将其复制到文件中.例如:

You can also specify property set hive.cli.print.header=true before the SELECT to ensure that header along with data is created and copied to file. For example:

hive -e 'set hive.cli.print.header=true; select * from your_Table' | sed 's/[	]/,/g'  > /home/yourfile.csv

如果您不想写入本地文件系统,请使用 hadoop fs -putsed 命令的输出通过管道返回到 HDFS代码>命令.

If you don't want to write to local file system, pipe the output of sed command back into HDFS using the hadoop fs -put command.

使用 Cyber​​duck 之类的东西 SFTP 到您的文件也可能很方便,或者您可以使用 scp 通过终端/命令提示符连接.

It may also be convenient to SFTP to your files using something like Cyberduck, or you can use scp to connect via terminal / command prompt.

这篇关于如何将 Hive 表导出为 CSV 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆