Kyle
10/17/2024, 11:10 AMjay
10/17/2024, 9:08 PMdf = daft.from_glob_path(...)
df = df.where("size < 10000000000")
filepaths = df.to_pydict()["paths"]
df_files_under_10gb = daft.read_parquet(filepaths)
df_files_under_10gb = df_files_under_10gb.into_partitions(100)
df.write_parquet(...)jay
10/17/2024, 9:08 PMKyle
10/17/2024, 11:34 PMjay
10/18/2024, 12:27 AMKyle
10/18/2024, 12:30 AMjay
10/18/2024, 1:37 AM.repartition() but note that this is quite expensive and requires a full shuffle.
Otherwise, .into_partitions() is your best bet. You can control the file sizes by using daft.set_execution_config(_*parquet_target_filesize*_=…)Zac Steer
10/19/2024, 5:38 AMimport daft
import binpacking
# Read files and their sizes
df = daft.from_glob_path(…)
files = df.to_pylist()
uri_to_size = {f[“uri”]: f[“size”] for f in files}
# Binpack
max_bin_size = # Specify max bin size
bins = binpacking.to_constant_volume(uri_to_size, max_bin_size)
binned_files = [
{
“bin_id”: bin_id,
“uri”: uri,
“size”: size
}
for bin_id, bin in enumerate(bins)
for uri, size in bin.items()
]
# Group by bin, map groups
@daft.udf(return_type=daft.DataTypes.string())
def my_udf(group):
“””Aggregates the parquet files in the group, writing a new parquet file and returning its path”””
# think you have a lot of options here for what you actually use to process the parquet files
pass
df = daft.from_pylist(binned_files)
df = df.groupby(“bin_id”).map_groups(my_udf)
df.collect()
But I’m curious what do you actually want to do in your udf?
In the example above, daft is basically just acting as a fancy ray/local dispatcher, depending on which runner you use.
You could accomplish the same thing with a thread pool executor and the ray python client. It’d just be a little lower level.
If you modeled the udf in more native daft expressions, think you wouldn’t have to worry about binpacking.
Also curious if by even sized files, are you saying you want each group worker to have an even sized input? Or do you want all group workers to produce an even sized output?Kyle
10/21/2024, 9:06 AM