Skip to main content

I have two input features. One contains the actual data, but with the wrong attribute names. The other contains the desired attribute names plus the connection key.

Data-Feature


Attributename-Feature


Green corresponds to the attribute name in the data feature,
Red is the name of the attribute in the end
 

How can I merge the two features and/or rename them so that the correct names appear?

 

Hi ​@michaels ,

A possible way is, merge the data-feature to the attributename-feature with FeatureJoiner or FeatureMerger, assign the data value to an attribute associated by the original attribute value (uuid) with AttributeDereferencer.

However, as you can see in the screenshot above, the method requires the same number of AttributeDereferencers as the number of target attributes. If there are many attributes, maybe scripting would be better.


I think you are potentially needing to use a Feature Reader to read Data-Feature and its ‘schema’ port attribute{}.name list. Obviously you’ll need to understand list manipulation Tutorial-Getting-Started-with-List-Attributes

Once you have a field with the UUID you can potentially use another feature reader/merge to bring in the Attributenames-feature. From here you what to update the attribute{} list index with the ‘name’ column. You finally connect the featureReader schema and data ports into a Writer. This is known as dynamic writing. More info Dynamic-Workflows-Components 


Another option would be to use the SchemaMapper, see https://support.safe.com/hc/en-us/articles/25407599862157-Tutorial-SchemaMapper-Transformer for a tutorial


Hi ​@michaels ,

A possible way is, merge the data-feature to the attributename-feature with FeatureJoiner or FeatureMerger, assign the data value to an attribute associated by the original attribute value (uuid) with AttributeDereferencer.

However, as you can see in the screenshot above, the method requires the same number of AttributeDereferencers as the number of target attributes. If there are many attributes, maybe scripting would be better.

Hi ​@takashi 

thanks very much for your idea. Is there a way to dereferencing the attributes dynamically? Because it's a dynamic workbench and I don't know what attributes come in.

thanks for your help again 😊


I would replace the AttributeDereferencers with a PythonCaller, if the attribute names are unknown when creating the workspace.

A script example:

class FeatureProcessor(object):
def __init__(self):
pass

def input(self, feature: fmeobjects.FMEFeature):
# create a dictionary associating attribute name with its value
d = {n : feature.getAttribute(n) for n in feature.getAllAttributeNames()}

# replace attribute value with data referenced by the original value (uuid)
for name, value in d.items():
newValue = d.get(value, None)
if newValue != None:
feature.setAttribute(name, newValue)

self.pyoutput(feature)