Github user mateiz commented on a diff in the pull request:
https://github.com/apache/spark/pull/455#discussion_r13147714
--- Diff: python/pyspark/context.py ---
@@ -311,6 +311,98 @@ def wholeTextFiles(self, path, minPartitions=None):
return RDD(self._jsc.wholeTextFiles(path, minPartitions), self,
PairDeserializer(UTF8Deserializer(),
UTF8Deserializer()))
+ def sequenceFile(self, name, key_class="org.apache.hadoop.io.Text",
value_class="org.apache.hadoop.io.Text",
+ key_wrapper="", value_wrapper="", minSplits=None):
+ """
+ Read a Hadoop SequenceFile with arbitrary key and value Writable
class from HDFS,
+ a local file system (available on all nodes), or any
Hadoop-supported file system URI.
+ The mechanism is as follows:
+ 1. A Java RDD is created from the SequenceFile or other
InputFormat, and the key and value Writable classes
+ 2. Serialization is attempted via Pyrolite pickling
+ 3. If this fails, the fallback is to call 'toString' on each
key and value
+ 4. C{PickleSerializer} is used to deserialize pickled objects
on the Python side
+ >>> sorted(sc.sequenceFile(tempdir +
"/sftestdata/sfint/").collect())
+ [(1, u'aa'), (1, u'aa'), (2, u'aa'), (2, u'bb'), (2, u'bb'), (3,
u'cc')]
+ >>> sorted(sc.sequenceFile(tempdir +
"/sftestdata/sfdouble/").collect())
+ [(1.0, u'aa'), (1.0, u'aa'), (2.0, u'aa'), (2.0, u'bb'), (2.0,
u'bb'), (3.0, u'cc')]
+ >>> sorted(sc.sequenceFile(tempdir +
"/sftestdata/sftext/").collect())
+ [(u'1', u'aa'), (u'1', u'aa'), (u'2', u'aa'), (u'2', u'bb'),
(u'2', u'bb'), (u'3', u'cc')]
+ >>> sorted(sc.sequenceFile(tempdir +
"/sftestdata/sfbool/").collect())
+ [(1, False), (1, True), (2, False), (2, False), (2, True), (3,
True)]
+ >>> sorted(sc.sequenceFile(tempdir +
"/sftestdata/sfnull/").collect())
+ [(1, None), (1, None), (2, None), (2, None), (2, None), (3, None)]
+ >>> sorted(sc.sequenceFile(tempdir +
"/sftestdata/sfmap/").collect())
+ [(1, {2.0: u'aa'}), (1, {3.0: u'bb'}), (2, {1.0: u'aa'}), (2,
{1.0: u'cc'}), (2, {3.0: u'bb'}), (3, {2.0: u'dd'})]
+ >>> r = sorted(sc.sequenceFile(tempdir +
"/sftestdata/sfclass").collect())[0]
+ >>> r == (u'1', {u'__class__':
u'org.apache.spark.api.python.TestWritable', u'double': 54.0, u'int': 123,
u'str': u'test1'})
+ True
--- End diff --
Nit: instead of having doctests here, it would be better to put a test in
`pyspark/tests.py` for this particular case. The reason is that doctests should
ideally be self-contained and should also serve as documentation, but these
depend on some files that the reader of the docs won't know about.
Instead, maybe add `@param` statements for the arguments. Look at
`pyspark/conf.py` to see how to format these in Epydoc.
---
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.
---