如何将Hive表导出为CSV文件? [英] How to export a Hive table into a CSV file?
问题描述
我使用此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 11或更高版本可以使用 INSERT
语句与 LOCAL
关键字。
If you're using Hive 11 or better you can use the INSERT
statement with the LOCAL
keyword.
示例:
insert overwrite local directory '/home/carter/staging' row format delimited fields terminated by ',' select * from hugetable;
请注意,这可能会创建多个文件,您可能希望在完成后将它们连接到客户端导出。
Note that this may create multiple files and you may want to concatenate them on the client side after it's done exporting.
使用这种方法意味着您不需要担心源表的格式,可以根据任意SQL查询导出,并且可以选择自己的分隔符和输出格式。
Using this approach means you don't need to worry about the format of the source tables, can export based on arbitrary SQL query, and can select your own delimiters and output formats.
这篇关于如何将Hive表导出为CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!