Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1598#discussion_r15616738
  
    --- Diff: python/pyspark/sql.py ---
    @@ -951,16 +938,39 @@ def count(self):
             """
             return self._jschema_rdd.count()
     
    -    def _toPython(self):
    -        # We have to import the Row class explicitly, so that the 
reference Pickler has is
    -        # pyspark.sql.Row instead of __main__.Row
    -        from pyspark.sql import Row
    -        jrdd = self._jschema_rdd.javaToPython()
    -        # TODO: This is inefficient, we should construct the Python Row 
object
    -        # in Java land in the javaToPython function. May require a custom
    -        # pickle serializer in Pyrolite
    -        return RDD(jrdd, self._sc, BatchedSerializer(
    -            PickleSerializer())).map(lambda d: Row(d))
    +    def collect(self):
    +        """
    +        Return a list that contains all of the rows in this RDD.
    +
    +        Each object in the list is on Row, the fields can be accessed as
    +        attributes.
    +        """
    +        rows = RDD.collect(self)
    +        cls = _create_cls(self.schema())
    +        return map(cls, rows)
    +
    +    # convert Row in JavaSchemaRDD into namedtuple, let access fields 
easier
    --- End diff --
    
    You should expand this comment a bit, e.g. "Convert each object in the RDD 
to a Row with the right class for this SchemaRDD, so that fields can be 
accessed as attributes." Also this needs to appear in some kind of class 
comment at the top, e.g. say "This class receives raw tuples from Java but 
assigns a class to it in all its data-collection methods 
(mapPartitionsWithIndex, collect, take, etc) so that PySpark sees them as Row 
objects with named fields".


---
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.
---

Reply via email to