-
Notifications
You must be signed in to change notification settings - Fork 133
feat: reduce duplicate fields on join #1184
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
Merged
timsaucer
merged 7 commits into
apache:main
from
timsaucer:feat/reduce-duplicate-fields
Nov 10, 2025
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
44529d9
Add field to dataframe join to indicate if we should keep duplicate keys
timsaucer 1a5587c
Suppress expected warning
timsaucer 9882dd9
Minor: small tables rendered way too large
timsaucer 4f9f190
Rename from keep_duplicate_keys to drop_duplicate_keys
timsaucer 1e7f874
Add unit tests for dropping duplicate keys or not
timsaucer c1b9dc4
Update online docs
timsaucer 60cc49a
Update docs/source/user-guide/common-operations/joins.rst
timsaucer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -647,7 +647,6 @@ def test_unnest_without_nulls(nested_df): | |
| assert result.column(1) == pa.array([7, 8, 8, 9, 9, 9]) | ||
|
|
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good if new tests for keep_duplicate_keys=False or True were added. To ensure coverage, add tests verifying that passing keep_duplicate_keys=True preserves both columns. |
||
| @pytest.mark.filterwarnings("ignore:`join_keys`:DeprecationWarning") | ||
| def test_join(): | ||
| ctx = SessionContext() | ||
|
|
||
|
|
@@ -664,25 +663,38 @@ def test_join(): | |
| df1 = ctx.create_dataframe([[batch]], "r") | ||
|
|
||
| df2 = df.join(df1, on="a", how="inner") | ||
| df2.show() | ||
| df2 = df2.sort(column("l.a")) | ||
| table = pa.Table.from_batches(df2.collect()) | ||
|
|
||
| expected = {"a": [1, 2], "c": [8, 10], "b": [4, 5]} | ||
| assert table.to_pydict() == expected | ||
|
|
||
| df2 = df.join(df1, left_on="a", right_on="a", how="inner") | ||
| df2.show() | ||
| # Test the default behavior for dropping duplicate keys | ||
| # Since we may have a duplicate column name and pa.Table() | ||
| # hides the fact, instead we need to explicitly check the | ||
| # resultant arrays. | ||
| df2 = df.join(df1, left_on="a", right_on="a", how="inner", drop_duplicate_keys=True) | ||
| df2 = df2.sort(column("l.a")) | ||
| table = pa.Table.from_batches(df2.collect()) | ||
| result = df2.collect()[0] | ||
| assert result.num_columns == 3 | ||
| assert result.column(0) == pa.array([1, 2], pa.int64()) | ||
| assert result.column(1) == pa.array([4, 5], pa.int64()) | ||
| assert result.column(2) == pa.array([8, 10], pa.int64()) | ||
|
|
||
| expected = {"a": [1, 2], "c": [8, 10], "b": [4, 5]} | ||
| assert table.to_pydict() == expected | ||
| df2 = df.join( | ||
| df1, left_on="a", right_on="a", how="inner", drop_duplicate_keys=False | ||
| ) | ||
| df2 = df2.sort(column("l.a")) | ||
| result = df2.collect()[0] | ||
| assert result.num_columns == 4 | ||
| assert result.column(0) == pa.array([1, 2], pa.int64()) | ||
| assert result.column(1) == pa.array([4, 5], pa.int64()) | ||
| assert result.column(2) == pa.array([1, 2], pa.int64()) | ||
| assert result.column(3) == pa.array([8, 10], pa.int64()) | ||
|
|
||
| # Verify we don't make a breaking change to pre-43.0.0 | ||
| # where users would pass join_keys as a positional argument | ||
| df2 = df.join(df1, (["a"], ["a"]), how="inner") | ||
| df2.show() | ||
| df2 = df2.sort(column("l.a")) | ||
| table = pa.Table.from_batches(df2.collect()) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.