This is an automated email from the ASF dual-hosted git repository.

gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 3fd987606be4 [SPARK-46556][PYTHON][DOCS] Refine docstring for 
DataFrame.createGlobalTempView/createOrReplaceGlobalTempView
3fd987606be4 is described below

commit 3fd987606be4ce262faf055d8e71faea731513e6
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Tue Jan 2 16:10:36 2024 +0900

    [SPARK-46556][PYTHON][DOCS] Refine docstring for 
DataFrame.createGlobalTempView/createOrReplaceGlobalTempView
    
    ### What changes were proposed in this pull request?
    
    This PR proposes to improve the docstring of 
`DataFrame.createGlobalTempView` and `DataFrame.createOrReplaceGlobalTempView`.
    
    ### Why are the changes needed?
    
    For better usability.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes, it improves user-facing documentation.
    
    ### How was this patch tested?
    
    Manually ran the tests via:
    
    ```bash
    python/run-tests --python-executable=python3  --testnames 
'pyspark.sql.dataframe'
    ```
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #44552 from HyukjinKwon/SPARK-46556.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 python/pyspark/sql/dataframe.py | 44 ++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/python/pyspark/sql/dataframe.py b/python/pyspark/sql/dataframe.py
index 35caf3b68b7e..f138b817bd22 100644
--- a/python/pyspark/sql/dataframe.py
+++ b/python/pyspark/sql/dataframe.py
@@ -407,9 +407,6 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
     def createOrReplaceTempView(self, name: str) -> None:
         """Creates or replaces a local temporary view with this 
:class:`DataFrame`.
 
-        The lifetime of this temporary table is tied to the 
:class:`SparkSession`
-        that was used to create this :class:`DataFrame`.
-
         .. versionadded:: 2.0.0
 
         .. versionchanged:: 3.4.0
@@ -420,6 +417,11 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
         name : str
             Name of the view.
 
+        Notes
+        -----
+        The lifetime of this temporary table is tied to the 
:class:`SparkSession`
+        that was used to create this :class:`DataFrame`.
+
         Examples
         --------
         Example 1: Creating a local temporary view named 'people'.
@@ -448,10 +450,6 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
     def createGlobalTempView(self, name: str) -> None:
         """Creates a global temporary view with this :class:`DataFrame`.
 
-        The lifetime of this temporary view is tied to this Spark application.
-        throws :class:`TempTableAlreadyExistsException`, if the view name 
already exists in the
-        catalog.
-
         .. versionadded:: 2.1.0
 
         .. versionchanged:: 3.4.0
@@ -462,25 +460,38 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
         name : str
             Name of the view.
 
+        Notes
+        -----
+        The lifetime of this temporary view is tied to this Spark application.
+        throws :class:`TempTableAlreadyExistsException`, if the view name 
already exists in the
+        catalog.
+
         Examples
         --------
-        Create a global temporary view.
+        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")
-        >>> sorted(df.collect()) == sorted(df2.collect())
-        True
+        >>> df2.show()
+        +---+-----+
+        |age| name|
+        +---+-----+
+        |  2|Alice|
+        |  5|  Bob|
+        +---+-----+
 
-        Throws an exception if the global temporary view already exists.
+        Example 2: Attempting to create a duplicate global temporary view
 
         >>> df.createGlobalTempView("people")  # doctest: 
+IGNORE_EXCEPTION_DETAIL
         Traceback (most recent call last):
         ...
         AnalysisException: "Temporary table 'people' already exists;"
+
+        Example 3: Dropping a global temporary view
+
         >>> spark.catalog.dropGlobalTempView("people")
         True
-
         """
         self._jdf.createGlobalTempView(name)
 
@@ -501,21 +512,22 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
 
         Examples
         --------
-        Create a global temporary view.
+        Example 1: Creating a global temporary view with a DataFrame
 
         >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], 
schema=["age", "name"])
         >>> df.createOrReplaceGlobalTempView("people")
 
-        Replace the global temporary view.
+        Example 2: Replacing a global temporary view with a filtered DataFrame
 
         >>> df2 = df.filter(df.age > 3)
         >>> df2.createOrReplaceGlobalTempView("people")
-        >>> df3 = spark.sql("SELECT * FROM global_temp.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
-
         """
         self._jdf.createOrReplaceGlobalTempView(name)
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to