Question

Renaming an attribute name to a parameter value

  • 26 February 2013
  • 16 replies
  • 14 views

Badge
Is there a simple way to rename a attribute name so a user defined field name set in a customer transformer parameter?

16 replies

Badge
thanks david.   This is weird because inside the custom transformer it applies the name fine, however in the main workspace, what is shown is the $(published_parameter) syntax, and not the text for this paramater in the attribute list.
Userlevel 4
Yes, this is normal behavior. The new attribute name is only available during run-time of the workbench, since it is renamed according to your published parameter (i.e. dynamically).

 

 

A workaround would be to rename your attribute to a known string (constant) at the start of the workspace, then renaming it to the value of your published parameter just before the writer.

 

 

David
Badge +2

@jryan and @david_r, Using AttributeRenamer or AttributeManager to rename an attribute to a value represented in a published parameter results in error. See selection-157.png. Please kindly advise how you did this.

Userlevel 4

Hi

Which version of FME are you using? I just tested FME 2016.1 and it works fine.

FME 2015.1.3.1 didn't manage it, however, but you could accomplish the same using a PythonCaller:

import fmeobjects
def FeatureProcessor(feature):
    newName = FME_MacroValues['pEvent_Route_ID']
    value = feature.getAttribute('_pEvent_Route_ID')
    feature.setAttribute(newName, value)
    feature.removeAttribute('_pEvent_Route_ID')

David

Badge +2

Hi

Which version of FME are you using? I just tested FME 2016.1 and it works fine.

FME 2015.1.3.1 didn't manage it, however, but you could accomplish the same using a PythonCaller:

import fmeobjects
def FeatureProcessor(feature):
    newName = FME_MacroValues['pEvent_Route_ID']
    value = feature.getAttribute('_pEvent_Route_ID')
    feature.setAttribute(newName, value)
    feature.removeAttribute('_pEvent_Route_ID')

David

Thank you very much for your help!  Yes, it works in 2016.1 even though the UI does not provide a way to pick a parameter for the "Output Attribute."  For older versions, I could use follow your python code!

Badge +22

The only way I've successfully output a parameterized attribute name in a custom transformer is to use a StringConcatenator with the New Attribute set to the Custom transformer parameter and the string expression set to the temporary attribute (that you want to rename). Follow that by an AttributeRemover to remove the temp attribute, and you end up with a custom transformer (CT) that behaves like any other transformer in regards to propagating attributes.

 

 

ie if you set the AttributeName parameter on the CT to "abc' than the rest of the workspace will have access to the abc attribute. If you set it to a workspace parameter then the rest of the workspace will have access to $(UserAttr) which at runtime will be whatever the user specified.
Badge +2

@jdh, thanks for the work around!

Just communicated with Safe tech support on the case, FYI -

This issue has been previously reported as problem report PR# 58160 - Custom Transformer Framework: Undefined macro dereferenced in file. Development has reported that the issue is the published parameter looking reference in the output port or attribute name name. Because of how custom transformers work, that published parameter is prefixed so doesn't really exist at runtime. Hence the error. This attribute / output port was returned because the port name was automatically generated based on their condition.

@jryan and @david_r, Using AttributeRenamer or AttributeManager to rename an attribute to a value represented in a published parameter results in error. See selection-157.png. Please kindly advise how you did this.

I have been trying this with version 2018.0 and I am having zero luck renaming an attribute to a parameter value. I have try all the above, the PythonCaller, AttributeRenamer, etc. Is there something different in this version that is not allowing me to do this?

 

Badge +3
I have been trying this with version 2018.0 and I am having zero luck renaming an attribute to a parameter value. I have try all the above, the PythonCaller, AttributeRenamer, etc. Is there something different in this version that is not allowing me to do this?

 

@laura_day: I'm not sure if this is going to work, but have you tried using the BulkAttributeRenamer ?

 

Userlevel 4
I have been trying this with version 2018.0 and I am having zero luck renaming an attribute to a parameter value. I have try all the above, the PythonCaller, AttributeRenamer, etc. Is there something different in this version that is not allowing me to do this?

 

Can you maybe share a small sample workspace that demonstrates the issue here?
Userlevel 2
Badge +17

Why not surf FME Hub? I have several solutions published in the FME Hub for a long time. e.g.

  • 2DVectorCalculator (X/Y Component Attribute)
  • AttributeConcatenator (Destination Attribute)
  • AttributeListExploder (List Name)
  • ListElementExtractor (Destination Attributes)
  • ListStatisticsCalculator (Prefix of Statistics Attributes)

etc.

Note: Some of them are experimental. Depending on FME version, may not work as expected.

Badge +2

@jryan and @david_r, Using AttributeRenamer or AttributeManager to rename an attribute to a value represented in a published parameter results in error. See selection-157.png. Please kindly advise how you did this.

Does someone already have a simple solution to this?

Badge

How to set the attribute name to published parameter value in FME 2019.1 ?

Userlevel 1
Badge +11

How to set the attribute name to published parameter value in FME 2019.1 ?

Hi @fikusas,

Thanks for your question! I noticed that this original question was posted a very long time ago, would you be open to posting a new question and linking to this one for context? This will make your new question more visible for the Community to provide more helpful suggestions.

Badge

Hi @fikusas,

Thanks for your question! I noticed that this original question was posted a very long time ago, would you be open to posting a new question and linking to this one for context? This will make your new question more visible for the Community to provide more helpful suggestions.

Yeah, I'll post it as a new question. Thanks for suggestion.

Badge +6

The only way I've successfully output a parameterized attribute name in a custom transformer is to use a StringConcatenator with the New Attribute set to the Custom transformer parameter and the string expression set to the temporary attribute (that you want to rename). Follow that by an AttributeRemover to remove the temp attribute, and you end up with a custom transformer (CT) that behaves like any other transformer in regards to propagating attributes.

 

 

ie if you set the AttributeName parameter on the CT to "abc' than the rest of the workspace will have access to the abc attribute. If you set it to a workspace parameter then the rest of the workspace will have access to $(UserAttr) which at runtime will be whatever the user specified.

This was very helpful @jdh​ . Thanks! I was able to rename the attribute to a parameter by using the StringConcatenator as it would allow me to pull in the value of the existing attribute while at the same time renaming the field to the parameter.

  • Expression Results: Create New Attribute
  • New Attribute: siteid
  • StringExpresstion: @Value($(siteid_parameter))

Reply