Solved

Exposing Dynamically Generated Attributes

  • 11 May 2016
  • 8 replies
  • 138 views

Badge +1
  • Participant
  • 126 replies

I have a workspace that reads from a spreadsheet and dynamically makes attribute names based on a date column, with the values of the attributes being the services offered on that date, as shown.

While the Feature Inspector sees these attributes, they are not exposed in the canvas and the writer is not aware of them, even when I make a dynamic writer and set Schema Sources as "Schema from first feature". Doesn't work with AttributeExposer either, as it does not see these dynamically generated attributes.

The spreadsheet will have different dates every year. Is there a way to write these attributes dynamically into the writer?

Thanks

icon

Best answer by todd_davis 11 May 2016, 19:48

View original

8 replies

Userlevel 1
Badge +12

If they are always the same attributes names each time then you can just use the attributeexposer, as you mentioned. It won't show them in the drop-down but that doesn't matter. You just need to expose them regardless

Badge +22

Are the date attributes in the original spreadsheet?

 

If so, then using a dynamic writer and Schema Sources set to the spreadsheet reader should work.

 

 

If not, then check out https://knowledge.safe.com/articles/1051/dynamic-w...

You will need to explicitly add your dynamic attributes to the schema list. Python is probably the easiest way to do this.

Badge +1

Are the date attributes in the original spreadsheet?

 

If so, then using a dynamic writer and Schema Sources set to the spreadsheet reader should work.

 

 

If not, then check out https://knowledge.safe.com/articles/1051/dynamic-w...

You will need to explicitly add your dynamic attributes to the schema list. Python is probably the easiest way to do this.

The dates are in the original spreadsheet, but they are values in a column, not attributes. I don't think it is possible to turn values into schema this way.

Badge +1

If they are always the same attributes names each time then you can just use the attributeexposer, as you mentioned. It won't show them in the drop-down but that doesn't matter. You just need to expose them regardless

There were 286 dates, so I didn't want to manually enter them. Rather, I used a PythonCaller to create a csv file and populate it with each date that came through the tranformer. The result is:

2016-01-08,2016-01-15,2016-01-22,2016-01-29,2016-02-05,

Then in the AttributeExposer I ran the Import Attribute Names wizard and imported the csv file. I just have to do that again every time that the spreadsheet changes, but it is only once a year.

Badge +22

See attached workspace for a proof of concept of dynamically creating the attribute schema. All non fme attributes (hidden or exposed) are written out.

 

 

dynamicattributes.fmw
Badge +1

See attached workspace for a proof of concept of dynamically creating the attribute schema. All non fme attributes (hidden or exposed) are written out.

 

 

dynamicattributes.fmw

Thanks for that explanation, jdh. The Dynamic Workflows tutorial that you linked to above did not make sense to me, but it does now.

Badge +1

For those people who don't want to call Python you can use a Schema Reader to get the list of attribute names, turn that into a newline separated list and then submit that to a sub workspace with WorkspaceRunner as a static parameter. Then in a FeatureReader set the attributes to expose as the user parameter. Solved! After years of answers that 'it is not possible'.

It does require two workspaces linked by the WorkspaceRunner but I submit that this is a Safe Solution. There is a rumour that FME 2020 would do something like this but I cannot see it in the Beta.

Debug the second workspace by pasting the list printed to the log (without the quotes). The second workspace needs another schema reader and a FeatureReader which has a tab to list the attributes to expose which can be the input parameter list.

 

I added the fme_feature_type and deleted OBJECTID in the first workspace. Note that you have to read the schema again in the second workspace. This basic idea was posted by Robin that gave me the idea to extend it to a dynamic list. This list must be set at the beginning, a Variable is not acceptable.

 

Badge

For those people who don't want to call Python you can use a Schema Reader to get the list of attribute names, turn that into a newline separated list and then submit that to a sub workspace with WorkspaceRunner as a static parameter. Then in a FeatureReader set the attributes to expose as the user parameter. Solved! After years of answers that 'it is not possible'.

It does require two workspaces linked by the WorkspaceRunner but I submit that this is a Safe Solution. There is a rumour that FME 2020 would do something like this but I cannot see it in the Beta.

Debug the second workspace by pasting the list printed to the log (without the quotes). The second workspace needs another schema reader and a FeatureReader which has a tab to list the attributes to expose which can be the input parameter list.

 

I added the fme_feature_type and deleted OBJECTID in the first workspace. Note that you have to read the schema again in the second workspace. This basic idea was posted by Robin that gave me the idea to extend it to a dynamic list. This list must be set at the beginning, a Variable is not acceptable.

 

Hu @kimo​ - where exactly are you pasting from the log? Thanks for this idea but I am stuck at the list attribute - I've set up the list how you had it but when i pass that through the Workspace Runner to the Feature Reader all i get is a multi line attribute 'exposed' instead of the individual attributes. Also, what do you mean the list must be set at the beginning and not a variable - maybe this is where I'm lost - thanks!

Reply