DataFrameWriter.
sortBy
Sorts the output in each bucket by the given columns on the file system.
New in version 2.3.0.
a name of a column, or a list of names.
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'))