Database Reference
In-Depth Information
Using Views
Views are a way of persisting queries so that they can be treated like any
other table in Hive. They behave similarly to views in a relational database.
You can use CREATE VIEW to define a view based on a query:
CREATE VIEW customerSales AS
SELECT c.name, c.city, c.state, c.postalCode,
s.salesAmount,
FROM MsBigData.customer c JOIN sales s ON c.name =
s.customerName
WHERE c.state='FL';
Selecting from the view works like selecting from any table, except that the
logic of the original query is abstracted away:
SELECT * FROM customerSales
WHERE salesAmount > 50000;
One of the most powerful uses of views in Hive is to handle complex data
types. Often, these need to be flattened out for consumption by users or
other processes. If you are using a view, the purchases column in the
customer table could be flattened into two columns, and consumers of the
view wouldn't need to understand the collection structure:
CREATE VIEW customerPurchases AS
SELECT c.name, c.city, c.state, c.postalCode,
c.purchases['Food'] AS foodPurchase,
c.purchases['Lodging'] AS lodgingPurchase
FROM MsBigData.customer c
WHERE c.state='FL';
You can remove views by using the DROP VIEW statement:
DROP VIEW customerPurchases;
Creating Indexes for Tables
As mentioned in the section on creating tables, Hive doesn't support keys.
Because traditional relational databases create indexes by creating stores of
indexed values that link to the keys of records with those values, you might
Search WWH ::




Custom Search