Database Reference
In-Depth Information
Database Creation
To create a database in Impala, I use the CREATE DATABASE command. I enter the following SQL command in Hue's
Impala Query Editor to create the fuel database:
CREATE DATABASE fuel ;
After clicking the Execute button to form this text, I find that the database drop-down menu on the Hue's Impala
user interface has a new option: fuel. To use this database in a SQL script, I can now specify the USE option:
USE fuel ;
Alternatively, I could use the database name before the table name, as shown in this SELECT command:
SELECT * FROM fuel.customer ;
External Table Creation
A Hive external table is a table where you specify the location for data storage rather than using the default value. For
example, by using CREATE EXTERNAL TABLE , I can create an external table against an HDFS directory that contains
comma-separated files (CSV). When the table is dropped the data is not deleted. The following code creates an
external table called “consumption” in the fuel database and that table can then be used to investigate trends in
vehicle fuel consumption:
CREATE EXTERNAL TABLE fuel.consumption
(
myear STRING,
manufacturer STRING,
model STRING,
fclass STRING,
enginesz STRING,
cylinders STRING,
transmission STRING,
fuel STRING,
consumption1 STRING,
consumption2 STRING,
consumption3 STRING,
consumption4 STRING,
avefuel STRING,
co2 STRING
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION '/user/hue2/fuel_consumption/';
Because a CSV file uses commas as the column separators, the row following the end parenthesis [)] uses a
DELIMITED option to process the data:
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
 
Search WWH ::




Custom Search