-1

Hi I am trying to fetch big table from hive and then write a csv file . Is there any way where we can write the whole result set in one go in a file as iteration over rows for a table containing several millions of records takes time .

I dont want to do while(rs.next()).

Aman Mittal
  • 61
  • 3
  • 10

1 Answers1

2

You didn't mention the SQL environment but usually you can just use SQL like so:

SELECT * FROM [TABLENAME]
  INTO OUTFILE '[FILENAME]'
  FIELDS TERMINATED BY ','
  ENCLOSED BY '"'
  LINES TERMINATED BY '\n'

For Hive it should be similar to the following

INSERT OVERWRITE LOCAL DIRECTORY '[FILENAME]' 
SELECT * FROM [TABLENAME]

I can't be more specific on how to exactly separate fields since i have no access to Hive but the documentaion on this should help

Writing data into the filesystem from queries

CannedMoose
  • 509
  • 1
  • 10
  • 18