且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 Hive 表导出为 CSV 文件?

更新时间:2023-01-31 18:56:33

或使用这个

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 -put将 sed 命令的输出通过管道返回到 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.