RyanB
RyanB

Reputation: 1

Exporting Hive Table Data into .csv

This question may have been asked before, and I am relatively new to the HADOOP and HIVE language. So I'm trying to export content, as a test, to see if I am doing things correctly. The code is below.

Use MY_DATABASE_NAME;
INSERT OVERWRITE LOCAL DIRECTORY '/random/directory/test'
ROW FORMAT DELIMITED 
FIELDS TERMINATED BY ','  
LINES TERMINATED BY "\n"
SELECT date_ts,script_tx,sequence_id FROM dir_test WHERE date_ts BETWEEN '2018-01-01' and '2018-01-02';

That is what I have so far, but then it generates multiple files and I want to combine them into a .csv file or a .xls file, to be worked on. My question, what do I do next to accomplish this?

Thanks in advance.

Upvotes: 0

Views: 791

Answers (1)

Yog
Yog

Reputation: 23

You can achieve by following ways:

  1. Use single reducer in the query like ORDER BY <col_name>
  2. Store to HDFS and then use command hdfs dfs –getmerge [-nl] <src> <localdest>
  3. Using beeline: beeline --outputformat=csv2 -f query_file.sql > <file_name>.csv

Upvotes: 2

Related Questions