Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here. Want to know more about what has changed? Check out the Community News blog.

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

SOLVED Go to solution

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

New Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions

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'

8 REPLIES 8

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.

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

New Contributor

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

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'

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

New Contributor

Can i do same with JDBC driver in java?

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

Explorer

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

Highlighted

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

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

 

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

Explorer
Thanks pushyami, for the bit about adding a header

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

New Contributor
Great! This is helpful