pyspark.sql.DataFrame.createOrReplaceGlobalTempView#
- DataFrame.createOrReplaceGlobalTempView(name)[source]#
Creates or replaces a global temporary view using the given name.
The lifetime of this temporary view is tied to this Spark application.
New in version 2.2.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- namestr
Name of the view.
Examples
Example 1: Creating a global temporary view with a DataFrame
>>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"]) >>> df.createOrReplaceGlobalTempView("people")
Example 2: Replacing a global temporary view with a filtered DataFrame
>>> df2 = df.filter(df.age > 3) >>> df2.createOrReplaceGlobalTempView("people") >>> df3 = spark.table("global_temp.people") >>> sorted(df3.collect()) == sorted(df2.collect()) True
Example 3: Dropping a global temporary view >>> spark.catalog.dropGlobalTempView(“people”) True