6

How can I save my query results in a CSV file via the Impala Shell.

My Code:

impala-shell -q "use test;
select * from teams;
-- From this point I need to save the query results to /Desktop (for example).
"

The problem that I am getting is that I have to select the DB first and then operate the query, but I only see syntax commands that directly uses the query instead of using the DB and then the query.

3 Answers3

8

Found it.

impala-shell -B -o output.csv --output_delimiter=',' -q "use test;
select * from teams;"
  • 4
    if looking for adding header as well, then include `--print header` in the command. https://community.cloudera.com/t5/Interactive-Short-cycle-SQL/How-to-get-header-in-Impala-output-csv-file/td-p/52673 – prashanth Nov 30 '18 at 09:12
  • In Impala Shell v2.12.0-cdh5.16.2 it is `--print_header` – arun Apr 28 '20 at 15:55
1

You can use

impala-shell -B -q "select * from anylbi.tablename_1;" -o extract.csv
--print_header '--output_delimiter=,'

if you have a particular server you're trying to connect you can use the -i option and then the server name after impala-shell

Yags
  • 482
  • 1
  • 6
  • 18
0

eg:

Server : SERVER_NAME

Output File : output.csv

Database : test

Table name : teams

Delimiter : |

impala-shell -k -i SERVER_NAME --ssl -B -o output.csv --print_header --output_delimiter=| -q "use test; select * from teams";
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '22 at 14:52