Add a filter function to HOT

Bug #1633512 reported by Thomas Herve
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
Medium
Thomas Herve

Bug Description

We'd like a way to filter values from list natively in HOT. Currently you can do it with yaql, but it'd be more efficient to do it directly in Heat.

The interface would look like: {filter: [value, iterable]} would remove all instance of value from iterable, and return the corresponding new iterable.

Tags: spec-lite
Thomas Herve (therve)
Changed in heat:
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to heat (master)

Fix proposed to branch: master
Review: https://review.openstack.org/387277

Changed in heat:
status: New → In Progress
Revision history for this message
huangtianhua (huangtianhua) wrote :

Do we support to filter several values from list? Something like:
filter:
  - ['a', 'b']
  - ['a', 'b', 'c', 'd']
which returns ['c', 'd']

Revision history for this message
Crag Wolfe (cwolfe) wrote :

Two unrelated comments.

1) I also like the idea of being able to filter several values from the list.

FWIW, this works right now:

{filter: [[4, 5], [[1, 2], 3, [4, 5]]] }
returns
[[1, 2], 3]

but I'd still rather the first argument be a list of things to filter, so the above case would instead look like
{filter: [[[4, 5]], [[1, 2], 3, [4, 5]]] }

2) What if a map is the iterable argument?

Should
{'filter': [1, { 1:2, 2:3 } ] }

Result in {2:3} or [2] (as it does right now in the patch) or an exception?

I lean toward {2:3} .

Revision history for this message
Thomas Herve (therve) wrote :

So for now, I'm tempted to not do those 2 things. It seems to go in the direction 'why not do that', instead of 'why we need to do that'. The first thing can be easily done with nesting. Supporting maps doesn't seem super useful either. We could raise an error if you feel strongly about it.

Revision history for this message
Crag Wolfe (cwolfe) wrote :

I agree my 2 comments are a bit on the way of feature creep. On the other hand, we want as little churn in the template functions as possible, IMO. So, for 1), if it turns out that filtering multiple things is desirable, we would need a new template function (unless you do nesting, as you suggest, but doing 10 nested calls to filter out 10 things feels a bit icky).

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/387277
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=df674a715b15aebf785a834324c759e5c58f91e1
Submitter: Jenkins
Branch: master

commit df674a715b15aebf785a834324c759e5c58f91e1
Author: Thomas Herve <email address hidden>
Date: Sat Oct 15 20:57:51 2016 +0200

    Add filter function

    Add a new HOT intrinsic function to filter out values from lists.

    Closes-Bug: #1633512
    Change-Id: Ie90001e6436b5ed5b29db7d3c166aba42299d3df

Changed in heat:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/heat 8.0.0.0b1

This issue was fixed in the openstack/heat 8.0.0.0b1 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.