pyspark.sql.DataFrameWriter.sortBy

DataFrameWriter.sortBy(col, *cols)[source]

Sorts the output in each bucket by the given columns on the file system.

New in version 2.3.0.

Parameters:
colstr, tuple or list

a name of a column, or a list of names.

colsstr

additional names (optional). If col is a list it should be empty.

Examples

>>> (df.write.format('parquet')  
...     .bucketBy(100, 'year', 'month')
...     .sortBy('day')
...     .mode("overwrite")
...     .saveAsTable('sorted_bucketed_table'))