cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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
Valued Contributor
Valued Contributor

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

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!