Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(join): joining on different types #3716

Merged
merged 9 commits into from
Jan 29, 2025
Merged

Conversation

kevinzwang
Copy link
Member

@kevinzwang kevinzwang commented Jan 21, 2025

This PR fixes a few things and also has some QOL changes.
Fixes:

  • Joining on null-type join keys
  • Joining on empty table (resolves Joins on empty tables give exceptions #3071) which turned out to be the above issue
  • Joining on join keys with different types
  • Combined column typing (right and outer joins should not just give left column types)

QOL:

  • Combine all the column renaming parameters into a JoinOptions type. Reduces the parameters for a bunch of functions and also uses the builder pattern
  • Rename keep_join_keys field to merge_matching_join_keys to make behavior more clear

@kevinzwang kevinzwang changed the title fix: joining on different types fix(join): joining on different types Jan 21, 2025
@github-actions github-actions bot added the fix label Jan 21, 2025
Copy link

codspeed-hq bot commented Jan 21, 2025

CodSpeed Performance Report

Merging #3716 will degrade performances by 44.76%

Comparing kevin/fix-join-diff-types (449742e) with main (de5acf5)

Summary

❌ 1 regressions
✅ 26 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_iter_rows_first_row[100 Small Files] 122.3 ms 221.4 ms -44.76%

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 87.73006% with 40 lines in your changes missing coverage. Please review.

Project coverage is 77.56%. Comparing base (fec399e) to head (449742e).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/daft-logical-plan/src/ops/join.rs 56.71% 29 Missing ⚠️
src/daft-dsl/src/expr/mod.rs 84.00% 4 Missing ⚠️
src/daft-local-execution/src/pipeline.rs 80.00% 3 Missing ⚠️
src/daft-logical-plan/src/treenode.rs 50.00% 2 Missing ⚠️
src/daft-dsl/src/join.rs 98.63% 1 Missing ⚠️
...local-execution/src/sinks/outer_hash_join_probe.rs 98.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3716      +/-   ##
==========================================
- Coverage   77.58%   77.56%   -0.02%     
==========================================
  Files         729      728       -1     
  Lines       92010    92054      +44     
==========================================
+ Hits        71389    71406      +17     
- Misses      20621    20648      +27     
Files with missing lines Coverage Δ
daft/dataframe/dataframe.py 85.51% <ø> (+0.11%) ⬆️
daft/logical/builder.py 90.65% <100.00%> (+0.37%) ⬆️
src/daft-dsl/src/lib.rs 100.00% <ø> (ø)
src/daft-local-plan/src/translate.rs 96.69% <100.00%> (+0.06%) ⬆️
src/daft-logical-plan/src/builder/mod.rs 91.61% <100.00%> (-0.06%) ⬇️
src/daft-logical-plan/src/display.rs 98.02% <100.00%> (-0.04%) ⬇️
src/daft-logical-plan/src/lib.rs 100.00% <100.00%> (ø)
...lan/src/optimization/rules/eliminate_cross_join.rs 88.09% <ø> (ø)
...lan/src/optimization/rules/filter_null_join_key.rs 98.62% <100.00%> (-0.06%) ⬇️
...al-plan/src/optimization/rules/push_down_filter.rs 97.35% <ø> (ø)
... and 13 more

... and 7 files with indirect coverage changes

Comment on lines -1458 to +1459
null_equals_nulls: list[bool] | None,
how: JoinType,
null_equals_nulls: list[bool] | None = None,
Copy link
Member Author

@kevinzwang kevinzwang Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small drive-by fix in typing to match rust definition


use crate::{deduplicate_expr_names, ExprRef};

pub fn get_common_join_cols<'a>(
Copy link
Member Author

@kevinzwang kevinzwang Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common columns now determined via schema instead of join keys so that join keys can be modified (ex: casting to supertype) without side effects. This does introduce a small API change in the order of the join schema: common columns are now sorted by left side schema instead of by join keys. I think this is fine but we could introduce a project under the left side to reorder if necessary.

@kevinzwang kevinzwang marked this pull request as ready for review January 22, 2025 01:21
Copy link
Contributor

@universalmind303 universalmind303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some initial comments. Will get to a more thorough review tomorrow!

join_prefix: str | None = None,
join_suffix: str | None = None,
join_strategy: JoinStrategy | None = None,
column_renaming_params: JoinColumnRenamingParams | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer deprecating join_prefix and join_suffix instead of just flat out removing them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm kind of also on the fence of leaving these as is for the dataframe api. IMO, it's a bit cleaner to do

df.join(df2, prefix="df2.", suffix="_joined")

instead of

from daft.daft import JoinColumnRenamingParams

df.join(df2, column_renaming_params=JoinColumnRenamingParams(prefix="df2.", suffix="_joined"))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API for the actual dataframe operation has not changed, this is just for the builder. Do you think we should be concerned about breaking the builder API?

Comment on lines +95 to +96
let left_on = deduplicate_expr_names(&left_on);
let right_on = deduplicate_expr_names(&right_on);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we make deduplicate_expr_names take in an iter so we don't have to materialize twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to materialize here anyway to get the DaftResult out of the iterator as well as split the iterator into two vecs.

@kevinzwang kevinzwang enabled auto-merge (squash) January 29, 2025 19:09
@kevinzwang kevinzwang merged commit d00e444 into main Jan 29, 2025
40 of 41 checks passed
@kevinzwang kevinzwang deleted the kevin/fix-join-diff-types branch January 29, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Joins on empty tables give exceptions
2 participants