Save Impala Shell query results in CSV
Asked Answered
U

3

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.

Underling answered 14/4, 2018 at 16:4 Comment(0)
U
9

Found it.

impala-shell -B -o output.csv --output_delimiter=',' -q "use test;
select * from teams;"
Underling answered 14/4, 2018 at 16:12 Comment(2)
if looking for adding header as well, then include --print header in the command. community.cloudera.com/t5/Interactive-Short-cycle-SQL/…Pedestrianism
In Impala Shell v2.12.0-cdh5.16.2 it is --print_headerXeniaxeno
P
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

Poler answered 9/5, 2019 at 14:4 Comment(0)
U
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";
Urmia answered 5/1, 2022 at 12:45 Comment(1)
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.Illconditioned

© 2022 - 2024 — McMap. All rights reserved.