Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

impala ALTER VIEW


May 26, 2021 impala


Table of contents


Impala's Alter View statement is used to change the view. W ith this statement, you can change the name of the view, change the database, and the queries associated with it.

Because the view is a logical structure, no physical data is affected by the alter view query.

Grammar

The following is the syntax of the Alter View statement

ALTER VIEW database_name.view_name为Select语句

Cases

For example, suppose you have a my_db called a view in the customers_view in Impala that contains the following.

+----------+-----+ 
| name     | age | 
+----------+-----+ 
| Komal    | 22  | 
| Khilan   | 25  | 
| Ramesh   | 32  | 
| Hardik   | 27  | 
| Chaitali | 25  | 
| kaushik  | 23  | 
+----------+-----+

The following is an example of an Alter View statement. In this example, we add columns id, name, and salary instead of name andage to customers_view.

[quickstart.cloudera:21000] > Alter view customers_view as select id, name, 
salary from customers;

When performing the query above, Impala customers_view changes to the data and displays the following message.

Query: alter view customers_view as select id, name, salary from customers

Verify

You can use the select statement to verify the contents customers_view view named The View, as shown below.

[quickstart.cloudera:21000] > select * from customers_view;
Query: select * from customers_view

This will result in the following results.

+----+----------+--------+ 
| id | name     | salary | 
+----+----------+--------+
| 3  | kaushik  | 30000  | 
| 2  | Khilan   | 15000  | 
| 5  | Hardik   | 40000  | 
| 6  | Komal    | 32000  | 
| 1  | Ramesh   | 20000  | 
| 4  | Chaitali | 35000  | 
+----+----------+--------+ 
Fetched 6 row(s) in 0.69s

Use Hue to change the view

Open the Impala query editor, select the context my_db, type the Alter View statement in it, and then click the execute button, as shown in the screenshot below.

impala ALTER VIEW

After the query is executed, the view named sample is changed accordingly.