CiscoDevNet / intersight-powershell

Cisco Intersight PowerShell
Apache License 2.0
16 stars 4 forks source link

Aggregation using -Apply does not return aggregated results #87

Open dchosnek opened 1 year ago

dchosnek commented 1 year ago

The GroupBy/Aggregate operation of the API shown below works using the API explorer (return a list of all server models found in an Intersight account and the number of servers of each model). When attempting this same operation using the PowerShell SDK, a list of objects is returned that does not contain either model names or a count of the model names.

GET /api/v1/compute/RackUnits?$apply=groupby((Model), aggregate($count as Total))

The operation does return the right number of objects, implying that "GroupBy" is working. But the contents of the objects are not useful.

To reproduce:

(Get-IntersightComputeRackUnit -Apply 'groupby((Model), aggregate($count as Total))').Results

This is one of the objects returned when running the above command in my Intersight account. Again, the command returns seven objects like this and there are seven different models in my Intersight account.

Name                       : Model
Type                       : Property
HasValues                  : True
First                      : {}
Last                       : {}
Count                      : 1
Parent                     : {Model, Total}
Root                       : {Model, Total}
Next                       : {}
Previous                   : 
Path                       : Model
LineNumber                 : 0
LinePosition               : 0
IsReadOnly                 : False
AllowNew                   : True
AllowEdit                  : True
AllowRemove                : True
SupportsChangeNotification : True
SupportsSearching          : False
SupportsSorting            : False
IsSorted                   : False
SortProperty               : 
SortDirection              : Ascending
IsFixedSize                : False
SyncRoot                   : System.Object
IsSynchronized             : False

Version used Intersight.PowerShell 1.0.9.6484 PowerShell 7.2.4

Expected behavior The API browser returns:

{
  "ObjectType": "mo.AggregateTransform",
  "Results": [
    {
      "Model": "UCSC-C240-M4S",
      "Total": 1
    },
    {
      "Model": "HXAF220C-M5SX",
      "Total": 12
    },
    {
      "Model": "HX220C-M4S",
      "Total": 8
    },
    {
      "Model": "HXAF220C-M4S",
      "Total": 8
    },
    {
      "Model": "UCSC-C240-M5L",
      "Total": 4
    },
    {
      "Model": "UCSC-C240-M5SX",
      "Total": 1
    },
    {
      "Model": "UCSC-C220-M4S",
      "Total": 24
    }
  ]
}

I would expect the PowerShell SDK to return something like:

Model          Total
-----          -----
UCSC-C240-M4S   1
HXAF220C-M5SX   12
HX220C-M4S      8
HXAF220C-M4S    8
UCSC-C240-M5L   4
UCSC-C240-M5SX  1
UCSC-C220-M4S   24
Ghufz commented 1 year ago

This is bug due to the underlying properties type as object. we are working on it. We have workaround for the same

 $test = Get-IntersightComputeRackUnit -Apply 'groupby((Model), aggregate($count as Total))' -Json
 $testResult = $test | ConvertFrom-Json
 $testResult.Results