How do I output the results of a HiveQL query to CSV?

前端 未结 18 1722
独厮守ぢ
独厮守ぢ 2020-11-27 10:11

we would like to put the results of a Hive query to a CSV file. I thought the command should look like this:

insert overwrite directory \'/home/output.csv\'          


        
18条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 11:05

    This is most csv friendly way I found to output the results of HiveQL.
    You don't need any grep or sed commands to format the data, instead hive supports it, just need to add extra tag of outputformat.

    hive --outputformat=csv2 -e 'select * from  limit 20' > /path/toStore/data/results.csv
    

提交回复
热议问题