Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ def createGlobalTempView(self, name):
"""
self._jdf.createGlobalTempView(name)

@since(2.2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we didn't merge the original PR to 2.2 right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the backport PR #18167

def createOrReplaceGlobalTempView(self, name):
"""Creates or replaces a global temporary view using the given name.

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

>>> df.createOrReplaceGlobalTempView("people")
>>> df2 = df.filter(df.age > 3)
>>> df2.createOrReplaceGlobalTempView("people")
>>> df3 = spark.sql("select * from people")

@dongjoon-hyun dongjoon-hyun May 30, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df3 = spark.sql("select * from global_temp.people")?

>>> sorted(df3.collect()) == sorted(df2.collect())
True
>>> spark.catalog.dropGlobalTempView("people")

"""
self._jdf.createOrReplaceGlobalTempView(name)

@property
@since(1.4)
def write(self):
Expand Down
1 change: 1 addition & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,7 @@ class Dataset[T] private[sql](
* view, e.g. `SELECT * FROM _global_temp.view1`.
*
* @group basic
* @since 2.2.0
*/
def createOrReplaceGlobalTempView(viewName: String): Unit = withPlan {
createTempViewCommand(viewName, replace = true, global = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class GlobalTempViewSuite extends QueryTest with SharedSQLContext {
// We can also use Catalog API to drop global temp view
spark.catalog.dropGlobalTempView("src2")
intercept[NoSuchTableException](spark.table(s"$globalTempDB.src2"))

// We can also use Dataset API to replace global temp view
Seq(2 -> "b").toDF("i", "j").createOrReplaceGlobalTempView("src")
checkAnswer(spark.table(s"$globalTempDB.src"), Row(2, "b"))
}

test("global temp view is shared among all sessions") {
Expand Down