Search code examples
hivehiveqlambarihiveddl

Hive views not reflecting base table changes


I have a number Views in Hive. Most of the views were created using a pattern select * rather than specific column names. When a column was removed from the base table, all these views started throwing missing column errors. I couldn't even do a select * from myview.

It appears that although my original view creation text is select *, Hive appear to have converted them into an extended format such as select col1, col2, col3 etc.

Is there a workaround or setting that I should enable, so that changes are reflected in views without needing to recreate them.


Solution

  • Hive is using stored view definitions.

    In SQL:200n, a view definition is supposed to be frozen at the time it is created, so that if the view is defined as select * from t, where t is a table with two columns a and b, then later requests to select * from the view should return just columns a and b, even if a new column c is later added to the table. This is implemented correctly by most DBMS products. See more details in this design document: Stored View Definition

    So, you need to perform ALTER VIEW [db_name.]view_name AS select_statement; command to reflect DDL changes. Alter View As Select changes the definition of a view, which must exist. The syntax is similar to that for CREATE VIEW and the effect is the same as for CREATE OR REPLACE VIEW. See more details here: Alter View.