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

[Bug]: LeftJoin produces duplicated results! #943

Closed
bakhtvar opened this issue Sep 10, 2024 · 4 comments · Fixed by #945
Closed

[Bug]: LeftJoin produces duplicated results! #943

bakhtvar opened this issue Sep 10, 2024 · 4 comments · Fixed by #945
Assignees
Labels

Comments

@bakhtvar
Copy link

bakhtvar commented Sep 10, 2024

Describe the bug 🐞

Simply the code below its expected to iterate and generate 3 outputs.

            var leftPart = new[] { 1, 2, 3 };
            var rightPart = new[] { 4, 6, 2 };
            leftPart.AsObservableChangeSet(x => 2 * x)
                .LeftJoin(rightPart.AsObservableChangeSet(x => x), x => x, (a, b) => new { a, b })
                .Transform(x => x)
                .Subscribe();

but after generating 3 output. it goes back and generates another 3, thus 6 in total!
If I Change it to RightJoin it works as expected, and generates only 3 results.

Step to reproduce

I just put the source code. A few lines of code.

Reproduction repository

https://github.com/reactivemarbles/DynamicData

Expected behavior

This should happen...
1,2
2,4
3,6

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

DynamicData Version

No response

Additional information ℹ️

No response

@bakhtvar bakhtvar added the bug label Sep 10, 2024
@JakenVeina
Copy link
Collaborator

What's your definition of "duplicated results"? There is no duplication that I can see.

If I take your exact snippet and toss in a .Bind() right before the .Subscribe() I can see the final state of the collection as...

{ a = 1, b = {2} }
{ a = 2, b = {4} }
{ a = 3, b = {6} }

@bakhtvar
Copy link
Author

Let me elaborate more...

            var leftSide = new[] { 1, 2, 3 };
            var rightSide = new[] { 4, 6, 2 };
            leftSide.AsObservableChangeSet(x => 2 * x)
                .LeftJoin(rightSide.AsObservableChangeSet(x => x), x => x, (a, b) => new { a, b })
                .Transform(x =>
                {
                    Debug.WriteLine(x);
                    return x;
                })
                .Subscribe();

generates the following

{ a = 1, b = 2 }
{ a = 2, b = 4 }
{ a = 3, b = 6 }
{ a = 2, b = 4 }
{ a = 3, b = 6 }
{ a = 1, b = 2 }

While if I change the code to RightJoin

            var leftSide = new[] { 1, 2, 3 };
            var rightSide = new[] { 4, 6, 2 };
            leftSide.AsObservableChangeSet(x => 2 * x)
                .RightJoin(rightSide.AsObservableChangeSet(x => x), x => x, (a, b) => new { a, b })
                .Transform(x =>
                {
                    Debug.WriteLine(x);
                    return x;
                })
                .Subscribe();

I will get this

{ a = 2, b = 4 }
{ a = 3, b = 6 }
{ a = 1, b = 2 }

So the RightJoin is correct, but LeftJoin provides 3 extra outputs.

P.S.
It is clear that if you bind the output those 6 output will overwrite and ultimately will have 3.

@JakenVeina
Copy link
Collaborator

Okay, so you're concerned about redundant transforms.

It looks like this was an issue with .RightJoin() and .InnerJoin() as well, that was coincidentally fixed 2 years ago, in #596. That was an optimization specific to .RightJoin() and .InnerJoin() so .LeftJoin() didn't get included.

The same fix seems to be working. I'll add some tests and implement it.

Copy link

github-actions bot commented Jan 7, 2025

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants