Reply
New Contributor
Posts: 4
Registered: ‎08-20-2014
Accepted Solution

How can I export query results to a csv file in Impala shell?

How can I export query results to a csv file in Impala shell?

Explorer
Posts: 10
Registered: ‎02-12-2014

Re: How can I export query results to a csv file in Impala shell?

You can use -o filename or --output_file filename & --output_delimiter=character options to generate output in csv file format.

New Contributor
Posts: 4
Registered: ‎08-20-2014

Re: How can I export query results to a csv file in Impala shell?

Thanks a lot for the response, I tried that but somehow its not working, do you have any sample example...

Explorer
Posts: 10
Registered: ‎02-12-2014

Re: How can I export query results to a csv file in Impala shell?

Try below syntax. Remove -k if your environment is not kerberosized -

 

impala-shell -k -i servername:portname -B -q 'select * from table' -o filename '--output_delimiter=\001'

Highlighted
New Contributor
Posts: 7
Registered: ‎06-29-2015

Re: How can I export query results to a csv file in Impala shell?

Can i do same with JDBC driver in java?

Explorer
Posts: 11
Registered: ‎03-25-2017

Re: How can I export query results to a csv file in Impala shell?

This command produces an output file but there is no header.  How can I produce an output csv file with a header?

New Contributor
Posts: 1
Registered: ‎03-31-2017

Re: How can I export query results to a csv file in Impala shell?

[ Edited ]

I was trying to out put a query to a file after ssh into the server where impala was running. This is the query that i used impala-shell -B -q 'select * from requests limit 1' -o query_result.txt '--output_delimiter=,'

 

Here is the another way to have a complex query/queries(delimited by ;) in a file and output result to a file

impala-shell -B -f my-query.txt -o query_result.txt '--output_delimiter=,'

 

 

adding headers to the output data

impala-shell -B -f my-query.txt -o query_result.txt --print_header '--output_delimiter=,'

 

Explorer
Posts: 11
Registered: ‎03-25-2017

Re: How can I export query results to a csv file in Impala shell?

Thanks pushyami, for the bit about adding a header
New Contributor
Posts: 2
Registered: ‎08-22-2017

Re: How can I export query results to a csv file in Impala shell?

Great! This is helpful