May 26, 2021 impala
Once connected to Impala, you need to select one from the available databases. I mpala's USE DATABASE statement is used to switch the current session to another database.
The following is the syntax of the USE statement.
USE db_name;
The following is an example of a USE statement. F irst, let's create a database called sample_database, as shown below.
> CREATE DATABASE IF NOT EXISTS sample_database;
This creates a new database and gives you the following output.
Query: create DATABASE IF NOT EXISTS my_db2 Fetched 0 row(s) in 2.73s
If you use the SHOW DATABASES statement to validate the database list, you can observe the name of the 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 use theUSE statement to switch the session to the newly created database (sample_database), as shown below.
> USE sample_database;
This changes the current context to sample_database and displays a message like the one shown below.
Query: use sample_database
On the left side of Impala's query editor, you'll see a drop-down menu, as shown in the screenshot below.
If you click the drop-down menu, you'll find a list of all databases in Impala, as shown below.
Simply select the database that needs to change the current context.