且构网

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

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

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

如果您使用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.