3

Suppose I have one feature per attribute country that is linked to a complex list attribute called stations with the sub-attributes name and platforms that looks like this:

station{0}.name     Gare du Nord
station{0}.platforms    32
station{0}.name     Hamburg Hbf
station{0}.platforms    12
station{1}.name     Munich Hbf
station{1}.platforms    32
station{2}.name     Frankfurt(Main) Hbf
station{2}.platforms    29
station{0}.name     Utrecht Centraal
station{0}.platforms    16
station{1}.name     Amsterdam Centraal
station{1}.platforms    11

The ListExploder would give me this (table 1):

country element_index name platforms
France 0 Gare du Nord 32
Germany 0 Hamburg Hbf 12
Germany 1 Munich Hbf 32
Germany 2 Frankfurt(Main) Hbf 29
The Netherlands 0 Utrecht Centraal 16
The Netherlands 1 Amsterdam Centraal 11

However, I need a transposed version of the table, where a new attribute is created for each combination of index and sub-attribute in the list attribute (table 2):

country station{0}.name station{0}.platforms station{1}.name station{1}.platforms station{2}.name station{2}.platforms
France Gare du Nord 32
Germany Hamburg Hbf 12 Munich Hbf 32 Frankfurt(Main) Hbf 29
The Netherlands Utrecht Centraal 16 Amsterdam Centraal 11

As you can see, the number of indices (stations) in the list attribute differs per feature (country), resulting in a dynamic allocation of attributes.

How can I transpose the contents of a list to get a table structure like in table 2 with FME?

I'm using FME Workbench 2021.2

1 Answer 1

3

Try using the ListBreaker transformer (it's a custom transformer from off of the FME Hub). It'll convert your list attributes {1},{2},{3} to attribute_1,_2,_3

enter image description here

enter image description here

Hoping this is what you were looking for.

3
  • Hi Mark, thanks for the solution, the ListBreaker looks great, however, I noticed that the attributes are not exposed by the ListBreaker. So if I inspect it, there are only the attributes name and platforms with empty values. When I use the AttributeExposer, I can expose the new columns manually (which requies knowing upfront all the names of the attributes). Is there a way to expose them automatically?
    – saQuist
    Commented Feb 6, 2023 at 11:09
  • Sorry, I don't think it's possible for me to do. I can't add an AttributeExposer to the custom transformer because I don't know what the attributes will be called, and it doesn't work if I try to set it programmatically (because FME doesn't know what they will be called). But if you write the data and the attributes are defined in your schema, then the data would get written without needing to be exposed. Commented Feb 17, 2023 at 18:49
  • 1
    Thank you for the follow-up. Using the schema upon export sounds like the way to go. Coming from programming languages like Python and R, these hidden and exposed attributes are just not that intuitive.
    – saQuist
    Commented Feb 22, 2023 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.