reactivemarbles/DynamicData

[Bug]: LeftJoin produces duplicated results!

Opened this issue ยท 3 comments

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

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} }

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.

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.