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 2019/03/01 21:52:36 UTC

[GitHub] srowen commented on a change in pull request #23548: [SPARK-26620][PYTHON] Make `DataFrameReader.json()` and `csv()` in Python should accept DataFrame.

srowen 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_r261770133
 
 

 ##########
 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:
   I'd also say this is working as intended. on the scala side it makes sense to support `Dataset[String]` and an `RDD[String]` is the closest analog here in Pyspark. It's easy to select a column out of a DataFrame 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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org