holdenk commented on code in PR #60000:
URL: https://github.com/apache/spark/pull/60000#discussion_r4590614924


##########
python/pyspark/sql/session.py:
##########
@@ -1990,6 +1993,53 @@ def table(self, tableName: str) -> DataFrame:
 
         return DataFrame(self._jsparkSession.table(tableName), self)
 
+    def getOrCreate(self, path: str, create: Callable[[], DataFrame]) -> 
DataFrame:
+        """Returns the :class:`DataFrame` stored at ``path``, computing and 
storing it first if
+        it is not already there. The dataset is stored as Parquet.
+
+        .. versionadded:: 4.4.0
+
+        Parameters
+        ----------
+        path : str
+            Directory holding the dataset. The caller supplies it, so a 
scheduled pipeline can
+            keep its runs apart by including a run identifier in it.
+        create : function
+            Zero-argument function returning the :class:`DataFrame` to store. 
It is called only
+            when ``path`` does not already hold a complete dataset.
+
+        Returns
+        -------
+        :class:`DataFrame`
+
+        Notes
+        -----
+        Supports Spark Classic only.
+
+        Completeness is tracked with a marker file written under ``path`` once 
the data is
+        stored, so a path left behind by an interrupted write is recomputed 
rather than read
+        back as if it were finished.
+
+        Examples
+        --------
+        >>> import tempfile
+        >>> with tempfile.TemporaryDirectory() as d:
+        ...     path = os.path.join(d, "ids")
+        ...     spark.getOrCreate(path, lambda: spark.range(3)).count()
+        ...     spark.getOrCreate(path, lambda: spark.range(100)).count()
+        3
+        3
+        """
+        assert self._jvm is not None
+        marker = self._jvm.org.apache.hadoop.fs.Path(path, 
_GET_OR_CREATE_MARKER)
+        fs = marker.getFileSystem(self._jsc.hadoopConfiguration())

Review Comment:
   I'd move this check inside a shared JVM function.



##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -9054,6 +9054,11 @@
           "Access to SparkSession Experimental (methods). This is server side 
developer API"
         ]
       },
+      "SESSION_GET_OR_CREATE" : {
+        "message" : [
+          "Invoking SparkSession 'getOrCreate'."
+        ]
+      },

Review Comment:
   I think we need to call this getOrCreateDataFrame since SparkSession 
getOrCreate (in my mind) maps to the SparkSession builder get or create.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to