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

Smarter property merge #12

Closed
iRon7 opened this issue Aug 11, 2020 · 1 comment
Closed

Smarter property merge #12

iRon7 opened this issue Aug 11, 2020 · 1 comment
Assignees

Comments

@iRon7
Copy link
Owner

iRon7 commented Aug 11, 2020

The idea started from the stackoverflow question: How to combine items from one PowerShell Array and one Powershell Object and produce a 3rd PowerShell Object?:

$vmSizelist = ConvertFrom-SourceTable '
    Name VMSize          ResourceGroup 
    VM1  Standard_D2s_v3 RG1
    VM2  Standard_D14_v2 RG2'

$AllVMSize = ConvertFrom-SourceTable '
    Name            NumberOfCores MemoryInMB MaxDataDiskCount OSDiskSizeInMB ResourceDiskSizeInMB
    Standard_B1ls               1        512                2        1047552                 4096
    Standard_B1ms               1       2048                2        1047552                 4096
    Standard_B1s                1       1024                2        1047552                 4096
    Standard_B2ms               2       8192                4        1047552                16384
    Standard_B2s                2       4096                4        1047552                 8192
    Standard_D2s_v3             2       8192                4        1047552                16384
    Standard_D14_v2            16     114688               64        1047552               819200'

$vmSizeList | LeftJoin $AllVMSize -On VMSize -Eq Name | Format-Table

Currently result in:

Name                   VMSize          ResourceGroup NumberOfCores MemoryInMB MaxDataDiskCount OSDiskSizeInMB ResourceDiskSizeInMB
----                   ------          ------------- ------------- ---------- ---------------- -------------- --------------------
{VM1, Standard_D2s_v3} Standard_D2s_v3 RG1                       2       8192                4        1047552                16384
{VM2, Standard_D14_v2} Standard_D14_v2 RG2                      16     114688               64        1047552               819200

Where the right part of the Name property (Name[1]) is actually redundant with the VMSize column because they are related by the -On parameter (where VMSize -Eq Name). In other words, in such a case the name property can be simplified to just: {$Left.$_}:

Name VMSize          ResourceGroup NumberOfCores MemoryInMB MaxDataDiskCount OSDiskSizeInMB ResourceDiskSizeInMB
---- ------          ------------- ------------- ---------- ---------------- -------------- --------------------
VM1  Standard_D2s_v3 RG1                       2       8192                4        1047552                16384
VM2  Standard_D14_v2 RG2                      16     114688               64        1047552               819200

The same goes for the embedded example:
Note that related properties with the same name (where the -equals parameter is omitted) are already merged in the current implementation (prior 3.2.4)

PS C:\> $Employee

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

PS C:\> $Department

Name        Country
----        -------
Engineering Germany
Marketing   England
Sales       France
Purchase    France

PS C:\> $Employee | InnerJoin $Department -On Department -Equals Name -Discern Employee, Department | Format-Table

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

The DepartmentName column is redundant with the Department column, meaning this can be simplified to:

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

As the Department column and DepartmentName column are equal, meaning that only the Country column is divided in two (EmployeeCountry and DepartmentCountry) columns

@iRon7 iRon7 self-assigned this Aug 11, 2020
@iRon7
Copy link
Owner Author

iRon7 commented Oct 8, 2020

Implemented

@iRon7 iRon7 closed this as completed Oct 8, 2020
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

1 participant