Skip to content

Instantly share code, notes, and snippets.

@sofyan-ahmad
Created December 4, 2018 00:56
Show Gist options
  • Save sofyan-ahmad/f98bd67343faa81cc62fdda3de98eb99 to your computer and use it in GitHub Desktop.
Save sofyan-ahmad/f98bd67343faa81cc62fdda3de98eb99 to your computer and use it in GitHub Desktop.
Export Hive to CSV
— Step 1: Create CSV table with dummy header column as first row.
CREATE TABLE table_csv_export_data
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘,’
LINES TERMINATED BY ‘\n’
STORED as textfile
AS
select
‘id’ as id
,’first_name’ as first_name
,’last_name’ as last_name
,’join_date’ as join_date;
— Step 2: Now insert data actual data into table
INSERT INTO table_csv_export_data
SELECT
id
,first_name
,last_name
,join_date
FROM
table_orc_data;
— Step 3
hadoop fs -cat hdfs://servername/user/hive/warehouse/databasename/table_csv_export_data/* > ~/output.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment