Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/8444#discussion_r38018765
--- Diff: python/pyspark/sql/readwriter.py ---
@@ -125,23 +131,33 @@ def load(self, path=None, format=None, schema=None,
**options):
@since(1.4)
def json(self, path, schema=None):
"""
- Loads a JSON file (one object per line) and returns the result as
- a :class`DataFrame`.
+ Loads a JSON file (one object per line) or an RDD of Strings
storing JSON objects
+ (one object per record) and returns the result as a
:class`DataFrame`.
If the ``schema`` parameter is not specified, this function goes
through the input once to determine the input schema.
- :param path: string, path to the JSON dataset.
+ :param path: string represents path to the JSON dataset,
+ or RDD of Strings storing JSON objects.
:param schema: an optional :class:`StructType` for the input
schema.
- >>> df =
sqlContext.read.json('python/test_support/sql/people.json')
- >>> df.dtypes
+ >>> df1 =
sqlContext.read.json('python/test_support/sql/people.json')
+ >>> df1.dtypes
+ [('age', 'bigint'), ('name', 'string')]
+ >>> rdd = sc.textFile('python/test_support/sql/people.json')
+ >>> df2 = sqlContext.read.json(rdd)
+ >>> df2.dtypes
[('age', 'bigint'), ('name', 'string')]
"""
if schema is not None:
self.schema(schema)
- return self._df(self._jreader.json(path))
+ if isinstance(path, basestring):
+ return self._df(self._jreader.json(path))
+ elif isinstance(path, RDD):
+ return self._df(self._jreader.json(path._jrdd))
+ else:
+ raise Exception("path can be only string or RDD")
--- End diff --
+1
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]