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

3.0 broke #10

Closed
vbondzio opened this issue Jan 8, 2020 · 5 comments
Closed

3.0 broke #10

vbondzio opened this issue Jan 8, 2020 · 5 comments

Comments

@vbondzio
Copy link

vbondzio commented Jan 8, 2020

Hi iRon7,

fe81e70#diff-15113da25fb697cea65f4001c98394fe

broke join for me. I'd guess because my objects contain hashtables?

PS C:\Users\Valentin> $hostNumaInfo | InnerJoin-Object $hostPciInfo -On PciId -Equals Id  | Select-Object *

PS C:\Users\Valentin> $hostNumaInfo | Select-Object -First 1

TypeId            : 0
CpuID             : {11, 10, 9, 8...}
MemoryRangeBegin  : 0
MemoryRangeLength : 34259832832
PciId             : {0000:00:00.0, 0000:00:01.0, 0000:00:02.0, 0000:00:03.0...}

PS C:\Users\Valentin> $hostPciInfo | Select-Object -First 1      

Id           : 0000:00:00.0
ClassId      : 1536
Bus          : 0
Slot         : 0
Function     : 0
VendorId     : -32634
SubVendorId  : -32634
VendorName   : Intel Corporation
DeviceId     : 12032
SubDeviceId  : 0
ParentBridge :
DeviceName   : Xeon E7 v3/Xeon E5 v3/Core i7 DMI2

Just FYI and thanks for your continued work on this! It came in handy a good bit already.

Cheers,

Valentin

@iRon7
Copy link
Owner

iRon7 commented Jan 8, 2020

Hello Valentin,

Thank you for your feedback, I wasn't actually aware that hashtables were working. But I can imaging it did and that recent changes broke it.
I will investigate whether I can repair this feature and possibly include it to my tests for future support.

iRon7 added a commit that referenced this issue Jan 9, 2020
@iRon7
Copy link
Owner

iRon7 commented Jan 9, 2020

Hello Valentin,

I have uploaded a new version (3.2.1) which supports dictionaries (hash tables, ordered table, ...) for input. Besides, I have added some tests for this which means I am intended to continue to support this.

Note1: your example doesn't error anymore but doesn't output anything as PciIdappears to different (also by type: String[]) from Id (String), yet if you try -On TypeId -Equals Bus, it does return an object.

Note2: No matter what object types you input, you will always get a PSCustomObject for output (or a [System.Management.Automation.Internal.AutomationNull]::Value).

Just an example test:

$Employee =
	@{'Id' = 1; 'Name' = 'Aerts'; 'Country' = 'Belgium'; 'Department' = 'Sales'; 'Age' = 40; 'ReportsTo' = 5},
	@{'Id' = 2; 'Name' = 'Bauer'; 'Country' = 'Germany'; 'Department' = 'Engineering'; 'Age' = 31; 'ReportsTo' = 4},
	@{'Id' = 3; 'Name' = 'Cook'; 'Country' = 'England'; 'Department' = 'Sales'; 'Age' = 69; 'ReportsTo' = 1},
	@{'Id' = 4; 'Name' = 'Duval'; 'Country' = 'France'; 'Department' = 'Engineering'; 'Age' = 21; 'ReportsTo' = 5},
	@{'Id' = 5; 'Name' = 'Evans'; 'Country' = 'England'; 'Department' = 'Marketing'; 'Age' = 35; 'ReportsTo' = ''},
	@{'Id' = 6; 'Name' = 'Fischer'; 'Country' = 'Germany'; 'Department' = 'Engineering'; 'Age' = 29; 'ReportsTo' = 4}
	
$Department =
	@{'Name' = 'Engineering'; 'Country' = 'Germany'},
	@{'Name' = 'Marketing'; 'Country' = 'England'},
	@{'Name' = 'Sales'; 'Country' = 'France'},
	@{'Name' = 'Purchase'; 'Country' = 'France'}

$Employee | FullJoin $Department -On Country -Discern Employee, Department | Format-Table

Returns:

Id EmployeeName Country Department  Age ReportsTo DepartmentName
-- ------------ ------- ----------  --- --------- --------------
 1 Aerts        Belgium Sales        40         5
 2 Bauer        Germany Engineering  31         4 Engineering
 3 Cook         England Sales        69         1 Marketing
 4 Duval        France  Engineering  21         5 Sales
 4 Duval        France  Engineering  21         5 Purchase
 5 Evans        England Marketing    35           Marketing
 6 Fischer      Germany Engineering  29         4 Engineering

@iRon7 iRon7 closed this as completed Jan 9, 2020
@vbondzio
Copy link
Author

vbondzio commented Jan 9, 2020

Thanks for that! It never errored after 3.0 for me, just didn't output anything. I'll look for a different solution, until then I'll just keep https://raw.githubusercontent.com/iRon7/Join-Object/354916dfa845183db772c689e3beb83e65d05a6d/Join-Object.ps1 handy :-)
Thanks again for looking into it!

P.S.
Just in case we crossed our wires somewhere, it worked fine before 3.0, it didn't just not output anything.

$hostNumaInfo | InnerJoin-Object $hostPciInfo -On PciId -Equals Id  | Select-Object `
VendorName, DeviceName, 
@{ N = "VID"; E = {[String]::Format("{0:x}", $_.VendorId)}},
@{ N = "DID"; E = {[String]::Format("{0:x}", $_.DeviceId)}},
@{ N = "SVID"; E = {[String]::Format("{0:x}", $_.SubVendorId)}},
@{ N = "NUMA Node"; E = { $_.TypeId} } `
| Sort-Object -Property "NUMA Node","VendorName" | Format-Table -AutoSize
VendorName                      DeviceName                                              VID  DID  SVID NUMA Node
----------                      ----------                                              ---  ---  ---- ---------
Avago (LSI)                     PERC H730 Mini (blade)                                  1000 5d   1028         0
Intel Corporation               C610/X99 series chipset USB Enhanced Host Controller #1 8086 8d26 1028         0
Intel Corporation               C610/X99 series chipset PCI Express Root Port #8        8086 8d1e 0            0
Intel Corporation               C610/X99 series chipset USB Enhanced Host Controller #2 8086 8d2d 1028         0
(...)

@iRon7
Copy link
Owner

iRon7 commented Jan 9, 2020

Ok, we were indeed not at the same page.
Since version 2.6.0 I have internally implemented a hashtable to improve the performance (see e.g. Powershell Merge 2 lists Performance). This means that the right keys are now indexed and a binary search is performed to match the related objects, the downside is indeed that there is no longer a Truthy/Falsy comparison (I didn't realize this until now)

Quote from About Comparison Operators just above Equality Operators:

When the input to an operator is a scalar value, comparison operators return a Boolean value. When the input is a collection of values, the comparison operators return any matching values. If there are no matches in a collection, comparison operators do not return anything.

Usual comparison:

PS C:\> 1 -eq 1
True
PS C:\> 1 -eq 2
False

But if you compare a collection this happens:

PS C:\> 1,2,3 -eq 4
PS C:\> 1,2,3 -eq 2
2

Where a result of 2 thruty matches the expression 1,2,3 -eq 2.
Unfortunately this feature can't be implemented in a binary search (without losing the performance improvement).

Anyways, the good news is that you can still fall back on the old behavior by supplying an expression instead (where $Leftrepresents each object in the supplied $LeftObject input object list and $Rightrepresents each object in the supplied $RightObject input object list):

$hostNumaInfo | InnerJoin-Object $hostPciInfo {$Left.PciId -Eq $Right.Id}

Or (probably a little faster):

$hostNumaInfo | InnerJoin-Object $hostPciInfo {$Left.PciId -Contains $Right.Id}

@vbondzio
Copy link
Author

vbondzio commented Jan 9, 2020

That's great to know! Thanks for the explanation, I learned something :-)

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

No branches or pull requests

2 participants