HyukjinKwon commented on a change in pull request #23548: [SPARK-26620][PYTHON] 
Make `DataFrameReader.json()` and `csv()` in Python should accept DataFrame.
URL: https://github.com/apache/spark/pull/23548#discussion_r247838776
 
 

 ##########
 File path: python/pyspark/sql/readwriter.py
 ##########
 @@ -289,8 +294,14 @@ def func(iterator):
             keyed._bypass_serializer = True
             jrdd = keyed._jrdd.map(self._spark._jvm.BytesToString())
             return self._df(self._jreader.json(jrdd))
+        elif isinstance(path, DataFrame):
+            if len(path.schema) != 1 or not 
isinstance(path.schema[0].dataType, StringType):
+                raise TypeError("The DataFrame can contain only one String 
column: %s"
+                                % path.schema.simpleString())
+            jdataset = 
path._jdf.__getattr__('as')(self._spark._jvm.Encoders.STRING())
+            return self._df(self._jreader.json(jdataset))
         else:
-            raise TypeError("path can be only string, list or RDD")
+            raise TypeError("path can be only string, list, RDD or DataFrame")
 
 Review comment:
   Eh .. @ueshin, do you actually mind if we see how the discussion would go in 
https://github.com/apache/spark/pull/23534 before getting this in? I was 
thinking both are quite related.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to