pyspark.sql.DataFrame.createGlobalTempView — PySpark 4.1.0 documentation (original) (raw)
DataFrame.createGlobalTempView(name)[source]#
Creates a global temporary view with this DataFrame.
New in version 2.1.0.
Changed in version 3.4.0: Supports Spark Connect.
Parameters
namestr
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
Example 1: Creating and querying a global temporary view
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| +---+-----+
Example 2: Attempting to create a duplicate global temporary view
df.createGlobalTempView("people")
Traceback (most recent call last): ... AnalysisException: "Temporary table 'people' already exists;"
Example 3: Dropping a global temporary view
spark.catalog.dropGlobalTempView("people") True