Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Explorer

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

1 ACCEPTED SOLUTION

avatar
Contributor

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'

View solution in original post

9 REPLIES 9

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

avatar
Explorer

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

avatar
Contributor

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'

avatar
Explorer

Can i do same with JDBC driver in java?

avatar
Contributor

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

avatar
New Contributor

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=,'

 

avatar
Contributor
Thanks pushyami, for the bit about adding a header

avatar
New Contributor
Great! This is helpful

avatar
New Contributor

But it will not allow to append result of multiple impala queries. Can it be possible to have any option in the command will will allow user to add results of multiple impala queries result in same output file with headers specific to each query.