Skip to main content

createGlobalTempView

Creates a global temporary view with this DataFrame.

Syntax

createGlobalTempView(name: str)

Parameters

Parameter

Type

Description

name

str

Name of the view.

Notes

The lifetime of this temporary view is tied to this Spark application. throws TempTableAlreadyExistsException, if the view name already exists in the catalog.

Examples

Python
df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
df.createGlobalTempView("people")
df2 = spark.sql("SELECT * FROM global_temp.people")
df2.show()
# +---+-----+
# |age| name|
# +---+-----+
# | 2|Alice|
# | 5| Bob|
# +---+-----+

df.createGlobalTempView("people")
# Traceback (most recent call last):
# ...
# AnalysisException: "Temporary table 'people' already exists;"

spark.catalog.dropGlobalTempView("people")
# True