Impala Shell Commands and Interface

The impala-shell command works with any standard Unix toolchain. This page describes a variety of shell commands that can be used interactively or non-interactively.

The -q option allows you to run a single query without having to start the interactive interpreter. You can use this option to run impala-shell from a shell script or from a Python, Perl, or other script using the command invocation syntax.

The below example fetches the information from testdates table which is in dbTest database in Impala.

impala-shell -i quickstart.cloudera:21000 -d dbTest -q ‘select * from testdates’


refers to the impala-shell interpreter to specify the connection information for that instance of impalad.
quickstart.cloudera:21000 is the host and the port in which impala daemon is running.
 refers to the database to connect
-q refers to query

You can use the -f option to process a file that contains several SQL statements, such as a series of reports or DDL statements to build a group of tables and views.

The below execution executes the local file and remains in non-interactive mode. This will usually be implemented for batch processing.

impala-shell -f sample.sql

The —var option allows you to pass replacement variables to statements run by that impala-shell session, such as those in a script file processed with the -f option. On the command line, use the format —var=variable name=value to encode the substitution variable. The syntax $var:variable name is used to substitute the value within a SQL statement. CDH 5.7 / Impala 2.5 and higher support this feature.

You can save query output to a file using the -o option.

The -B switch disables nice printing, allowing you to output comma-separated, tab-separated, or other delimited text files. (To change the delimiter character, use the —output delimiter option; the tab character is the default.)

Non-interactive mode prints query output to stdout or the file given by the -o option, while accidental output is printed to stderr, allowing you to process only the query output as part of a Unix pipeline.

Below is the syntax.
impala-shell -i servername:portname -B -q ‘select * from table’ -o filename ‘–output_delimiter=\delimiter’

The below command exports the contents of the table into a file.

impala-shell -i quickstart.cloudera:21000
-d dbtest
-q ‘select * from region3’
-o region3results.csv

-d refers to database
-q refers to query

-o refers to output file name

The below command exports the query results into a file in a specified format

impala-shell -i quickstart.cloudera:21000 -B
-d dbtest
-q ‘select * from region3’
-o region3results.csv

Look at the screenshots for a better understanding.

Use the below command based on the Kerberos environment-

impala-shell -k -i quickstart.cloudera:21000 -B
-d dbtest
-q ‘select * from region3’
-o region3results.csv

Impala Interface:


Hope you liked this post.

Stay in touch for more interesting updates.

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s