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

    https://github.com/apache/spark/pull/17077#discussion_r115129884
  
    --- Diff: python/pyspark/sql/readwriter.py ---
    @@ -563,6 +563,60 @@ def partitionBy(self, *cols):
             self._jwrite = self._jwrite.partitionBy(_to_seq(self._spark._sc, 
cols))
             return self
     
    +    @since(2.3)
    +    def bucketBy(self, numBuckets, *cols):
    +        """Buckets the output by the given columns on the file system.
    +
    +        :param numBuckets: the number of buckets to save
    +        :param cols: name of columns
    +
    +        .. note:: Applicable for file-based data sources in combination 
with
    +                  :py:meth:`DataFrameWriter.saveAsTable`.
    +
    +        >>> (df.write.format('parquet')
    +        ...     .bucketBy(100, 'year', 'month')
    +        ...     .mode("overwrite")
    +        ...     .saveAsTable('bucketed_table'))
    +        """
    +        if len(cols) == 1 and isinstance(cols[0], (list, tuple)):
    +            cols = cols[0]
    +
    +        if not isinstance(numBuckets, int):
    +            raise TypeError("numBuckets should be an int, got 
{0}.".format(type(numBuckets)))
    +
    +        if not all(isinstance(c, basestring) for c in cols):
    +            raise TypeError("cols argument should be a string or a 
sequence of strings.")
    +
    +        col = cols[0]
    +        cols = cols[1:]
    +
    +        self._jwrite = self._jwrite.bucketBy(numBuckets, col, 
_to_seq(self._spark._sc, cols))
    +        return self
    +
    +    @since(2.3)
    +    def sortBy(self, *cols):
    +        """Sorts the output in each bucket by the given columns on the 
file system.
    +
    +        :param cols: name of columns
    +
    +        >>> (df.write.format('parquet')
    +        ...     .bucketBy(100, 'year', 'month')
    +        ...     .sortBy('day')
    +        ...     .mode("overwrite")
    +        ...     .saveAsTable('sorted_bucketed_table'))
    +        """
    +        if len(cols) == 1 and isinstance(cols[0], (list, tuple)):
    +            cols = cols[0]
    +
    +        if not all(isinstance(c, basestring) for c in cols):
    +            raise TypeError("cols argument should be a string or a 
sequence of strings.")
    --- End diff --
    
    same note as above.


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

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

Reply via email to