spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-13233][SQL] Python Dataset (basic versi...
Date Fri, 26 Feb 2016 22:04:15 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11347#discussion_r54308608
  
    --- Diff: python/pyspark/sql/dataframe.py ---
    @@ -257,53 +264,85 @@ def limit(self, num):
         @ignore_unicode_prefix
         @since(1.3)
         def take(self, num):
    -        """Returns the first ``num`` rows as a :class:`list` of :class:`Row`.
    +        """Returns the first ``num`` records as a :class:`list`.
     
             >>> df.take(2)
             [Row(age=2, name=u'Alice'), Row(age=5, name=u'Bob')]
             """
    -        with SCCallSiteSync(self._sc) as css:
    -            port = self._sc._jvm.org.apache.spark.sql.execution.python.EvaluatePython.takeAndServe(
    -                self._jdf, num)
    -        return list(_load_from_socket(port, BatchedSerializer(PickleSerializer())))
    +        return self.limit(num).collect()
     
         @ignore_unicode_prefix
    -    @since(1.3)
    -    def map(self, f):
    -        """ Returns a new :class:`RDD` by applying a the ``f`` function to each :class:`Row`.
    +    @since(2.0)
    +    def applySchema(self, schema=None):
    +        """Returns a new :class:`DataFrame` by appling the given schema, or infer the
schema
    +        by all of the records if no schema is given.
     
    -        This is a shorthand for ``df.rdd.map()``.
    +        It is only allowed to apply schema for DataFrame which is returned by typed operations,
    +        e.g. map, flatMap, etc. And the record type of the schema-applied DataFrame will
be row.
     
    -        >>> df.map(lambda p: p.name).collect()
    +        >>> ds = df.map(lambda row: row.name)
    +        >>> ds.collect()
             [u'Alice', u'Bob']
    +        >>> ds.schema
    +        StructType(List(StructField(value,BinaryType,false)))
    +        >>> ds2 = ds.applySchema(StringType())
    +        >>> ds2.collect()
    +        [Row(value=u'Alice'), Row(value=u'Bob')]
    +        >>> ds2.schema
    +        StructType(List(StructField(value,StringType,true)))
    +        >>> ds3 = ds.applySchema()
    +        >>> ds3.collect()
    +        [Row(value=u'Alice'), Row(value=u'Bob')]
    +        >>> ds3.schema
    +        StructType(List(StructField(value,StringType,true)))
    +        """
    +        msg = "Cannot apply schema to a DataFrame which is not returned by typed operations"
    +        raise RuntimeError(msg)
    --- End diff --
    
    Just Excaption


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message