How to Use Beeline to connect to Impala

You can certainly connect to Impala using Hive Driver from beeline, like below command:

beeline -u 'jdbc:hive2://<impala-daemon-host>:21050/default;auth=noSasl'

However, the result output format does not work properly:

> show tables;
customers
dim_prod
mansi
sample_07
sample_08
small
web_logs
+-------+--+
| name  |
+-------+--+
+-------+--+

Notice the output is not inside the columns?

The better approach is to use Cloudera Impala JDBC Driver, please follow the steps below:

1. Download the driver from Cloudera Impala JDBC Driver
2. Extract the files and put it somewhere on the host that you need to run beeline command, in my case is under /root/impala-jdbc/jdbc
3. Run the following command to update the HADOOP_CLASSPATH to include the Impala JDBC Driver JARs

export HADOOP_CLASSPATH=`hadoop classpath`:/root/impala-jdbc/jdbc/*

4. Finally you are ready to start beeline:

beeline -d "com.cloudera.impala.jdbc41.Driver" -u 'jdbc:impala://<impala-daemon-host>:21050;AuthMech=0'

You will need to tell beeline the class name for the driver using “-d” option, in my case the driver class is com.cloudera.impala.jdbc41.Driver

The output looks much better:

> show tables;
+------------+--+
|    name    |
+------------+--+
| customers  |
| dim_prod   |
| mansi      |
| sample_07  |
| sample_08  |
| small      |
| web_logs   |
+------------+--+
7 rows selected (0.219 seconds)

However, the best way is to connect from impala-shell which is designed for Impala natively.

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *