You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/08/09 10:16:37 UTC
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #37445: [SPARK-40015][PYTHON] Add sc.listArchives and sc.listFiles to PySpark
HyukjinKwon commented on code in PR #37445:
URL: https://github.com/apache/spark/pull/37445#discussion_r941160451
##########
python/pyspark/context.py:
##########
@@ -1249,9 +1249,37 @@ def addFile(self, path: str, recursive: bool = False) -> None:
... return [x * fileVal for x in iterator]
>>> sc.parallelize([1, 2, 3, 4]).mapPartitions(func).collect()
[100, 200, 300, 400]
+ >>> sc.listFiles
+ ['file:/.../test.txt']
+ >>> path2 = os.path.join(tempdir, "test2.txt")
+ >>> with open(path2, "w") as testFile:
+ ... _ = testFile.write("100")
+ >>> sc.addFile(path2)
+ >>> sc.listFiles
+ ['file:/.../test.txt', 'file:/.../test2.txt']
"""
self._jsc.sc().addFile(path, recursive)
+ @property
+ def listFiles(self) -> List[str]:
+ """Returns a list of file paths that are added to resources.
+
+ .. versionadded:: 3.4.0
+
+ See Also
+ --------
+ SparkContext.addFile
+ """
+ jfiles = self._jsc.sc().listFiles()
+ if jfiles is None:
+ return []
+ else:
+ files = []
Review Comment:
Maybe:
```python
list(self._jvm.scala.collection.JavaConverters.seqAsJavaList(self._jsc.sc().listFiles()))
```
Seems like it can't be `None` anyway.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org