[openstack-dev] [heat][yaql] Deep merge map of lists?
Thomas Herve
therve at redhat.com
Mon Aug 29 14:03:27 UTC 2016
On Mon, Aug 29, 2016 at 3:16 PM, Steven Hardy <shardy at redhat.com> wrote:
> On Mon, Aug 29, 2016 at 07:07:09AM +0200, Thomas Herve wrote:
>> dict($.groupBy($.keys().toList()[0], $.values().toList()[0][0]))
>>
>> ought to work, I believe?
>
> So, as it turns out, my example above was bad, and groupBy only works if
> you have a list of maps with exactly one key, we actually need this:
>
> # Example of tripleo format
> # We need an output of
> # "gnocchi_metricd_node_names": ["overcloud-controller-0"]
> # "tripleo_packages_node_names": ["overcloud-controller-0", "overcloud-compute-0"]
> # "nova_compute_node_names": ["overcloud-compute-0"]
> debug_tripleo:
> value:
> yaql:
> expression: dict($.data.l.groupBy($.keys().toList()[0], $.values().toList()[0][0]))
> data:
> l:
> - "gnocchi_metricd_node_names": ["overcloud-controller-0"]
> "tripleo_packages_node_names": ["overcloud-controller-0"]
> - "nova_compute_node_names": ["overcloud-compute-0"]
> "tripleo_packages_node_names": ["overcloud-compute-0"]
>
> So, I'm back to wondering how we make the intermediate assignement of tripleo_packages_node_names
Well I didn't know all the constraints :).
$.selectMany($.items()).groupBy($[0], $[1][0])
is another attempt. It won't work if you have more than one value per
key in the original data, but I think it will handle multiple keys.
--
Thomas
More information about the OpenStack-dev
mailing list