Views
Learning Objectives
u Views
u Types of views
View
u Logical query against source tables
A1 A4 B2 B3
A1 A2 A3 A4 B1 B2 B3 B4
table_1 table_2
view_x
CREATE VIEW view_x
AS SELECT A1, A4, B2, B3
FROM table_1
INNER JOIN table_2 …
Types of views
1. (Stored) Views
2. Temporary views
3. Global Temporary views
1- (Stored) Views
u Persisted objects
u CREATE VIEW view_name
AS query
2- Temporary view
u Session-scoped view
u CREATE TEMP VIEW view_name
AS query
Spark Session
u Opening a new notebook
u Detaching and reattaching to a cluster
u Installing a python package
u Restarting a cluster
3- Global Temporary views
u Cluster-scoped view
u CREATE GLOBAL TEMP VIEW view_name
AS query
u SELECT * FROM global_temp.view_name
Views comparison
(Stored) Views
u Persisted in DB
u Dropped only by
DROP VIEW
u CREATE VIEW
Global Temp views
u Cluster-scoped
u dropped when
cluster restarted
u CREATE GLOBAL
TEMP VIEW
Temp views
u Session-scoped
u dropped when
session ends
u CREATE TEMP VIEW

Views.pdf

  • 1.
  • 2.
  • 3.
    View u Logical queryagainst source tables A1 A4 B2 B3 A1 A2 A3 A4 B1 B2 B3 B4 table_1 table_2 view_x CREATE VIEW view_x AS SELECT A1, A4, B2, B3 FROM table_1 INNER JOIN table_2 …
  • 4.
    Types of views 1.(Stored) Views 2. Temporary views 3. Global Temporary views
  • 5.
    1- (Stored) Views uPersisted objects u CREATE VIEW view_name AS query
  • 6.
    2- Temporary view uSession-scoped view u CREATE TEMP VIEW view_name AS query
  • 7.
    Spark Session u Openinga new notebook u Detaching and reattaching to a cluster u Installing a python package u Restarting a cluster
  • 8.
    3- Global Temporaryviews u Cluster-scoped view u CREATE GLOBAL TEMP VIEW view_name AS query u SELECT * FROM global_temp.view_name
  • 9.
    Views comparison (Stored) Views uPersisted in DB u Dropped only by DROP VIEW u CREATE VIEW Global Temp views u Cluster-scoped u dropped when cluster restarted u CREATE GLOBAL TEMP VIEW Temp views u Session-scoped u dropped when session ends u CREATE TEMP VIEW