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

前端 未结 18 1680
独厮守ぢ
独厮守ぢ 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 10:54

    Just to cover more following steps after kicking off the query: INSERT OVERWRITE LOCAL DIRECTORY '/home/lvermeer/temp' ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' select books from table;

    In my case, the generated data under temp folder is in deflate format, and it looks like this:

    $ ls
    000000_0.deflate  
    000001_0.deflate  
    000002_0.deflate  
    000003_0.deflate  
    000004_0.deflate  
    000005_0.deflate  
    000006_0.deflate  
    000007_0.deflate
    

    Here's the command to unzip the deflate files and put everything into one csv file:

    hadoop fs -text "file:///home/lvermeer/temp/*" > /home/lvermeer/result.csv
    

提交回复
热议问题