cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

What's the difference between a Global view and a Temp view?

User15787040559
New Contributor III

The difference between Global and Temp is how the lifetime of the view is tied to the application:

http://spark.apache.org/docs/latest/api/python/reference/api/pyspark.sql.DataFrame.createOrReplaceTe...

Creates or replaces a local temporary view with this DataFrame.

The lifetime of this temporary table is tied to the SparkSession that was used to create this DataFrame.

http://spark.apache.org/docs/latest/api/python/reference/api/pyspark.sql.DataFrame.createOrReplaceGl...

Creates or replaces a global temporary view using the given name.

The lifetime of this temporary view is tied to this Spark application.

2 REPLIES 2

aladda
Honored Contributor II
Honored Contributor II

In the context of Databricks Notebooks and Clusters

  • A Temp View is available across the context of a Notebook and is a common way of sharing data across various language REPL - Ex:- Python to Scala.
  • A Global Temp View is available to all Notebooks running on that Databricks Cluster

ScottSmithDB
Contributor III
Contributor III

Correct A Temp View is scoped to the SparkSession and dropped when that session closes.  Each notebook runs in its own SparkSession.  The Global Temp View is scoped to the cluster and dropped when the cluster re-starts or you drop it.

----------------------------------------------------------------------

TEMPORARY

TEMPORARY views are visible only to the session that created them and are dropped when the session ends.

GLOBAL TEMPORARY

Applies to: check marked yes Databricks Runtime

GLOBAL TEMPORARY views are tied to a system preserved temporary schema global_temp.

https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-view.html

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.