Impala - Select a Database


Advertisements

Once you get connected to Impala, it is required to select one among the available databases. The USE DATABASE Statement of Impala is used to switch the current session to another database.

Syntax

Following is the syntax of USE Statement.

USE db_name;

Example

Following is an example of USE statement. First of all, let us create a database with the name sample_database as shown below.

> CREATE DATABASE IF NOT EXISTS sample_database;

This will create a new database and give you the following output.

Query: create DATABASE IF NOT EXISTS my_db2

Fetched 0 row(s) in 2.73s

If you verify the list of databases using the SHOW DATABASES statement, you can observe the name of newly created database in it.

> SHOW DATABASES;

Query: show DATABASES 
+-----------------------+ 
| name                  | 
+-----------------------+ 
| _impala_builtins      | 
| default               | 
| my_db                 | 
| sample_database       | 
+-----------------------+ 
Fetched 4 row(s) in 0.11s

Now, let’s switch the session to the newly created database (sample_database) using the USE Statement as shown below.

> USE sample_database;

This will change the current context to sample_database and display a message as shown below.

Query: use sample_database

Selecting a Database using Hue Browser

On the left-hand side of the Query Editor of Impala, you will find a dropdown menu as shown in the following screenshot.

Selecting a Database

If you click on the dropdown menu, you will find the list of all the databases in Impala as shown below.

 Selecting Databases Dropdown list

Simply select the database to which you need to change the current context.

Advertisements