Skip to main content
Question

Is there an easy way to extract a subset of values from a list attribute. For example if the list attribute contains: 1,3,5,6,8,10,5 etc up to hundreds of values, how can I extract the first 10 values as a list also?


Forum|alt.badge.img

Is there an easy way to extract a subset of values from a list attribute. For example if the list attribute contains: 1,3,5,6,8,10,5 etc up to hundreds of values, how can I extract the first 10 values as a list also?

12 replies

takashi
Influencer
  • April 30, 2020

Hi @johnm, the ListSlicer from FME Hub might help you.


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • April 30, 2020

Otherwise in the standard Transformers use a ListExploder which gives an option to assign an Element Index attribute which will be a sequence from Base 0 of 0,1,2,3,4...

A Tester on the output of the ListExploder using a Test criteria of Element Index < 10 will give the first 10 values in each List that was attributed against the base Features.

This can then be pushed back into Features with Lists by recompiling the Tester output with ListBuilder, now limited to a maximum of the first 10 List Items.


Forum|alt.badge.img
  • Author
  • April 30, 2020

Hi @bwn, I think that is the best solution as the ListSlicer that takashi suggested has a python compatability issue which I can't change on my work FME version as they are still at 2.7. Thanks again. John

 


Forum|alt.badge.img
  • Author
  • April 30, 2020

Hi @takashi, This is a good transformer and does what I want except there is a python compatabily issue when I download it. I cannot change this where I work as they are still using 2.7 and a new version may cause problems on FME Server. Thanks again, John

 


takashi
Influencer
  • April 30, 2020
johnm wrote:

Hi @takashi, This is a good transformer and does what I want except there is a python compatabily issue when I download it. I cannot change this where I work as they are still using 2.7 and a new version may cause problems on FME Server. Thanks again, John

 

The transformer supports both Python 2.7 and Python 3.x, so you can just change the Python Compatibility parameter to 3.x+ after adding the transformer.

Addition, I updated the transformer in the Hub to change the default Python version to 3.x+. You can also replace the transformer with the new one.


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • April 30, 2020
johnm wrote:

Hi @bwn, I think that is the best solution as the ListSlicer that takashi suggested has a python compatability issue which I can't change on my work FME version as they are still at 2.7. Thanks again. John

 

It's worth keeping an eye on performance. Whilst exploding and rebuilding the list will work, if your lists have hundreds of elements it may be much slower to do this than using the custom transformer or a python solution


util_ryan
  • April 30, 2020

You can use the AttributeKeeper to keep a certain amount of list attributes.

 

Make sure to select the list through 'Attributes to Keep' (and not 'Lists to Keep') and it will ask you to define a range of which list values to keep.

 


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • April 30, 2020

It's hardly elegant, but if it's just 10 values for one attribute, you could use an AttributeCopier; i.e. copy

alist{0}.myattribute to anotherlist{0}.myattribute
alist{1}.myattribute to anotherlist{1}.myattribute

...and so on, for all ten attributes.


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • April 30, 2020
util_ryan wrote:

You can use the AttributeKeeper to keep a certain amount of list attributes.

 

Make sure to select the list through 'Attributes to Keep' (and not 'Lists to Keep') and it will ask you to define a range of which list values to keep.

 

Oh, very good solution. I'd no idea that was even possible!


takashi
Influencer
  • May 1, 2020

If you always keep first 10 elements, the BulkAttributeRemove could also be an easy solution.

e.g.


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • May 1, 2020
takashi wrote:

If you always keep first 10 elements, the BulkAttributeRemove could also be an easy solution.

e.g.

Yes, similarly I thought the BulkAttributeRemover alternative would also work @takashi. It was some of your similar posts on using RegEx and BulkAttributeRenamer that really show how List Attributes are just Normal Attributes with an Attribute Name of ListName{indexvalue} and hence can be manipulated just like any other regular Attribute.

The only thing is it gets trickier to write the RegEx when you get variations of like "the first 35 elements" etc. , but from a performance perspective, one of the best ways of doing it rather than use ListExploder.


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • May 2, 2020
util_ryan wrote:

You can use the AttributeKeeper to keep a certain amount of list attributes.

 

Make sure to select the list through 'Attributes to Keep' (and not 'Lists to Keep') and it will ask you to define a range of which list values to keep.

 

Similarly that's a new one for me! I'd only every used a single index value rather than a range since that is the default Dialog value.....but I guess it pays to RTFM!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings