Database Reference
In-Depth Information
• A database is a logical entity to group related tables into one single
namespace.
• With Impala running on a DataNode, physically, a database in Impala is rep-
resented as a directory on
HDFS
. All internal tables, partitions, and data files
are saved inside the parent directory.
• An Impala database is created inside the Impala directory on HDFS with the
name
database_name.db
.
• The database directory on HDFS is the same as any other directory on HDFS
and supports all directory operations like any other directory.
Now let's learn a few database-specific statements in Impala.
The CREATE DATABASE statement
When there is a need to create a database, you can use the
CREATE DATABASE
statement to create a new database as follows:
CREATE (DATABASE|SCHEMA)
[IF NOT EXISTS] database_name [COMMENT
'database_comment']
[LOCATION hdfs_path];
The DROP DATABASE statement
To remove a database from Impala, you can use the
DROP DATABASE
statement.
Once the
DROP DATABASE
statement is executed, the corresponding
data-
base_name.db
directory from HDFS is removed. The syntax of the
DROP
DATABASE
statement is as follows:
DROP (DATABASE|SCHEMA) [IF EXISTS]
database_name;
There is no protection to the
DROP DATABASE
statement. If the
DROP DATABASE
statement is executed on a database that has tables and data files, all the content
will be removed from the HDFS, and the database directory will be deleted. So, it is
recommended that you must empty the database yourself before calling the
DROP
statement.