Global Temporary View
臨時觀點session-scoped
如果創建它的會話終止就會消失。
如果您希望臨時視圖在所有會話之間共享並保持活動狀態,直到Spark應用程序終止,您可以創建一個全局臨時視圖。全局臨時視圖與系統保存的數據庫global_temp綁定,我們必須使用限定名稱來引用它,例如, SELECT * FROM global_temp.view1。
// Register the DataFrame as a global temporary view
df.createGlobalTempView("people")
// Global temporary view is tied to a system preserved database `global_temp`
spark.sql("SELECT * FROM global_temp.people").show()
// +----+-------+
// | age| name|
// +----+-------+
// |null|Michael|
// | 30| Andy|
// | 19| Justin|
// +----+-------+
// Global temporary view is cross-session
spark.newSession().sql("SELECT * FROM global_temp.people").show()
// +----+-------+
// | age| name|
// +----+-------+
// |null|Michael|
// | 30| Andy|
// | 19| Justin|
// +----+-------+
Global Temporary View is not part of Spark 2.0.2 (latest) version.
Global Temporary View is part of next release