Yuri Gorokhov
10/25/2024, 11:55 PMdaft.col(join_key_left).hash() % n_partitions)
VS
daft.col(join_key_left).apply(lambda val: hash(val) % n_partitions, return_dtype=daft.DataType.int64()))
For the first, I get a very un-even distribution, for the second I get an even distribution. My guess is % expression is not doign what I think it's doing.Yuri Gorokhov
10/25/2024, 11:57 PMYuri Gorokhov
10/25/2024, 11:57 PMYuri Gorokhov
10/26/2024, 12:03 AMjay
10/26/2024, 12:10 AMjoin_key_left column?Yuri Gorokhov
10/26/2024, 2:20 AMYuri Gorokhov
10/26/2024, 2:21 AMimport daft
from daft import col
import random
import string
def rand_str():
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(20))
n_partitions = 10
df = daft.from_pydict({"col": [rand_str() for _ in range(10000)]})
print("Uniformly distributed")
df.with_column(
"hash",
daft.col("col").apply(lambda val: hash(val) % n_partitions, return_dtype=daft.DataType.uint16())) \
.groupby("hash").agg(
col("hash").count().alias("count")
) \
.show()
print("Non-uniformly distributed")
df.with_column(
"hash",
daft.col("col").hash() % n_partitions) \
.groupby("hash").agg(
col("hash").count().alias("count")
) \
.show()Yuri Gorokhov
10/26/2024, 2:22 AMUniformly distributed
╭────────┬────────╮
│ hash ┆ count │
│ --- ┆ --- │
│ UInt16 ┆ UInt64 │
╞════════╪════════╡
│ 9 ┆ 1001 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 5 ┆ 990 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2 ┆ 994 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 7 ┆ 984 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 1 ┆ 968 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 3 ┆ 1033 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 8 ┆ 992 │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 4 ┆ 993 │
╰────────┴────────╯
(Showing first 8 rows)
Non-uniformly distributed
╭─────────┬────────╮
│ hash ┆ count │
│ --- ┆ --- │
│ Float64 ┆ UInt64 │
╞═════════╪════════╡
│ 4 ┆ 1994 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 2 ┆ 2061 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 6 ┆ 1965 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 5 ┆ 1 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 9 ┆ 3 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 1 ┆ 1 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 0 ┆ 1976 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ 8 ┆ 1999 │
╰─────────┴────────╯Sammy Sidhu
10/26/2024, 3:01 AMSammy Sidhu
10/26/2024, 3:58 AMUInt64 and the signed literal that was passed in. The resultant type ended up being the float that you saw above which when was rehashed for the group by led to odd distribution you saw.
This however only affected the % operator when used with a literal like what you had.
When performing joins, group by or other partitioning operations, the distribution should be what we expect.
Heres the PR to fix this
It looks correct now! 🙂 Thanks for raising this issue!Yuri Gorokhov
10/27/2024, 2:27 AMYuri Gorokhov
10/27/2024, 2:38 AMHenry T
10/28/2024, 3:51 PM