iRon7 / Join-Object

Combines two objects lists based on a related property between them.
MIT License
107 stars 13 forks source link

-Property (vs. ommiting it) seems to cause odd behaviour #11

Closed vbondzio closed 4 years ago

vbondzio commented 4 years ago

Hi iRon7,

sorry for the blast but as far as I understand, the following examples shouldn't behave differently:

Doesn't work:

$hostNumaInfo | InnerJoin-Object $hostPciInfo {$Left.PciId -Contains $Right.Id} `
 | LeftJoin-Object $hostNicList {$Left.Id -Contains $Right.PCIDevice} `
 | LeftJoin-Object $hostHbaList -Property {$Left.Id -Contains $Right.PCIID} `
 | Select-Object VendorName, DeviceName, 
(...)

VendorName              DeviceName                                              PCI ID       VID  DID  SVID NUMA Node VMKernelName
----------              ----------                                              ------       ---  ---  ---- --------- ------------
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMI2                      0000:00:00.0 8086 2f00 15d9         0 vmhba0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 1   0000:00:01.0 8086 2f02 0            0 vmhba1
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 3   0000:00:03.0 8086 2f08 0            0 vmhba2
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 0             0000:00:04.0 8086 2f20 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 1             0000:00:04.1 8086 2f21 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 2             0000:00:04.2 8086 2f22 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 3             0000:00:04.3 8086 2f23 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 4             0000:00:04.4 8086 2f24 8086         0

Works:

$hostNumaInfo | InnerJoin-Object $hostPciInfo {$Left.PciId -Contains $Right.Id} `
 | LeftJoin-Object $hostNicList {$Left.Id -Contains $Right.PCIDevice} `
 | LeftJoin-Object $hostHbaList {$Left.Id -Contains $Right.PCIID} `
 | Select-Object VendorName, DeviceName, 
(...)

VendorName              DeviceName                                              PCI ID       VID  DID  SVID NUMA Node VMKernelName
----------              ----------                                              ------       ---  ---  ---- --------- ------------
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMI2                      0000:00:00.0 8086 2f00 15d9         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 1   0000:00:01.0 8086 2f02 0            0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 PCI Express Root Port 3   0000:00:03.0 8086 2f08 0            0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 0             0000:00:04.0 8086 2f20 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 1             0000:00:04.1 8086 2f21 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 2             0000:00:04.2 8086 2f22 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 3             0000:00:04.3 8086 2f23 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 4             0000:00:04.4 8086 2f24 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 5             0000:00:04.5 8086 2f25 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 6             0000:00:04.6 8086 2f26 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 DMA Channel 7             0000:00:04.7 8086 2f27 8086         0
Intel Corporation       Xeon E7 v3/Xeon E5 v3/Core i7 Hot Plug                  0000:00:05.1 8086 2f29 0            0
Intel Corporation       C610/X99 series chipset SPSR                            0000:00:11.0 8086 8d7c 8086         0
Intel Corporation       Wellsburg AHCI Controller                               0000:00:11.4 8086 8d62 8086         0 vmhba0
Intel Corporation       C610/X99 series chipset USB xHCI Host Controller        0000:00:14.0 8086 8d31 8086         0
(...)

When using "-Property", it seems to join to the first objects even though it doesn't match ...

Granted, it's late and I didn't spend much time on it, feel free to tell me to sod off :-)

Cheers,

Valentin

iRon7 commented 4 years ago

Hello Valentin,

There are two mutually exclusive parameters at position 2 (see also: Help Join):

  1. -On (possibly together with -Equals)
  2. -OnExpression

These two properties will be automatically recognized by the value type as -On is a String[] and -OnExpression is a ScriptBlock, both parameters determine which object at the left side will be joined with the object on the right side.

The -Property parameter, on the other hand, is a named property, meaning that you can't define the value without supplying it's name. The -Property parameter has a complete different function, it defines the properties of the output object. It is comparable with | Select-Object VendorName, DeviceName, (...) with the exception that you can refer back to the current $Left and $Right objects. e.g. To return the VendorName, DeviceName and concat the VID of the left and right object, you might do something like: -Property VendorName, DeviceName, @{VID = {$Left.$_ + '/' + $Right.$_}}.

Bottom line, you probably want to do this:

$hostNumaInfo | InnerJoin-Object $hostPciInfo {$Left.PciId -Contains $Right.Id} `
 | LeftJoin-Object $hostNicList {$Left.Id -Contains $Right.PCIDevice} `
 | LeftJoin-Object $hostHbaList -OnExpression {$Left.Id -Contains $Right.PCIID} `
 | Select-Object VendorName, DeviceName, 
(...)
vbondzio commented 4 years ago

I swear I actually read the help... re-reading it, I don't understand how I could misinterpreted it as much as I did. Thank you for the way nicer than necessary explanation!

iRon7 commented 4 years ago

No problem, note that you get more extensive help (including parameter positions) with Help Join than Join -? (or just reading it from the script).