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

FullJoin doesn't work properly when joining multiple array when one of the array is empty #28

Closed
sanjeev40084 opened this issue Jul 22, 2021 · 4 comments
Assignees
Labels

Comments

@sanjeev40084
Copy link

Create 2 new arrays and add data on first array and don't add any data on second array.

$arrayList1 = @()
$arrayList2 = @()

$arrayList1 += "james"
$arrayList1 += "henry"

$arrayList1 |FullJoin $arrayList2 -Name arrayList1, arrayList2

The output looks like this:

james
henry

Expected:

arrayList1 arrayList2
james
henry
@iRon7 iRon7 self-assigned this Jul 23, 2021
@iRon7 iRon7 added the bug label Jul 23, 2021
@iRon7
Copy link
Owner

iRon7 commented Jul 23, 2021

Thanks, for the information.
I looks like a bug. I do have some tests for empty arrays included but unfortunately only on inner joins.
I need some time to fix this.

@iRon7
Copy link
Owner

iRon7 commented Jul 27, 2021

At second sight, this issue not really a bug in this context but rather a high-level design limitation.
Let me explain...

First of all, there are a few features in this Join cmdlet that are related to this issue:

  • The ability to do a self-join (by omitting either the -LeftObject or RightObject)
  • The ability to do a side-by-side join (by omitting the -On parameter)
  • The ability to "paste" arrays containing scalar objects

This features are inferieur to the main purpose of this cmdlet: combine two object lists based on a related property between them. Nevertheless, I will do whatever is possible to support them all-in-one.

Taken:

$a = @('a1', 'a2')
$b = @('b1', 'b2')
$c = @('c1', 'c2')
$d = @('d1', 'd2')

I can join these arrays like:

$ab = $a |Join $b
$cd = $c |Join $c
$abcd = $ab |Join $cd
$abcd |% { "$_" }
a1 b1 c1 d1
a2 b2 c2 d2

Where:

  • $a is an array with a single dimension (1 column, 2 rows)
  • $ab is an array with two dimensions (2 columns, 2 rows)
  • $abcd is an array with two dimensions (4 columns, 2 rows)

Now question yourself: what exactly is @()?
It is an array with no dimensions: an array with zero rows and zero columns.
Implying that there is no way to determine how many columns it actually is supposed to have when it is filled.

Which changes the question to: how do I create an array with 1 (or more) columns but no rows?
You can do that using initiators like: [Object[]] where you define that the array has a single column that contains a list of (or zero) objects.

This was not working in previous versions either but implemented from version 3.5.4.
Meaning you can now do this:

$arrayList1 = [Object[]]@('james', 'henry')
$arrayList2 = [Object[]]@()

$arrayList1 |FullJoin $arrayList2 -Name arrayList1, arrayList2

arrayList1 arrayList2
---------- ----------
james
henry

Note:
Due to the nature of the PowerShell pipeline, @() |... (or [Object[]]@() |...) will not process any items, meaning:

[Object[]]@() |% { "Result" }

Will not show any result.
In other words, if also the left object lists is possibly empty (in an outer join), you will to supply the lists as arguments:

$arrayList1 = [Object[]]@()
$arrayList2 = [Object[]]@('james', 'henry')

FullJoin -Left $arrayList1 -Right $arrayList2 -Name arrayList1, arrayList2

arrayList1 arrayList2
---------- ----------
           james
           henry

iRon7 added a commit that referenced this issue Jul 27, 2021
iRon7 added a commit that referenced this issue Jul 27, 2021
iRon7 added a commit that referenced this issue Jul 27, 2021
iRon7 added a commit that referenced this issue Jul 27, 2021
@iRon7 iRon7 closed this as completed Jul 27, 2021
@sanjeev40084
Copy link
Author

@iRon7 if i have more than two arraylist what is the command to display all arraylist result?
i tried this but it only showed $arrayList2 and $arrayList3

FullJoin -Left $arrayList1 -Right $arrayList2, $arrayList3 -Name arrayList1, arrayList2, arrayList3
arrayList2 arrayList3
james test
henry

arraylist = didn't had value
arraylist2 = james, henry
arraylist3 = test

@iRon7
Copy link
Owner

iRon7 commented Aug 20, 2021

The easiest way to do this is chaining the join commands:

$arraylist1 = @()
$arraylist2 = 'james', 'henry'
$arraylist3 = 'test'

FullJoin -Left ([Object[]]$arrayList1) -Right $arrayList2 |FullJoin $arrayList3 -Name arrayList1, arrayList2, arrayList3

arrayList1 arrayList2 arrayList3
---------- ---------- ----------
           james      test
           henry

Note that you have to prefix the empty array with an initiator like [Object[]] to give it any dimensions (as fixed and explained in this original issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants