Skip to main content

I would like to create new attributes for all features with a value of null. The tricky part is that the number of these attributes and their names is not known before running the workflow. The names have to be equal to the feature values provided by some part of the workflow. I attach an image of what I am trying to do:

 

I am feeding the AttributeCreator with the main table (the one where I want to have new attributes --or columns -- with null values) and with the UnmergedRequestor of the Feature Merger. The feature values of SimWaterBodies_FN (the output of the UnmergedRequestor) are supposed to be the names of the new attributes (2 in this case) of the table.

 

I have tried by setting @Value(SimWaterBodies_FN) as the New Attribute and null as the Attribute Value of the Attribute Creator, but this doesn't create the 2 columns with same length of the main Table.

 

Here is a simple example of what I am trying to do:

 

Let's say this is the main Table initially:

 

 

When I run my workflow, the feature merger gives me the following output through the UnmergedRequestor:

These 2 values (Phophate and Ammonia) of SimWaterBodies_FN are the attributes that I have detected as "not present" in the main table. These depend on one of my input files, so if I change the input file it could be that SimWaterBodies_FN has more or less than 2 values.

 

 

The output I would like to obtain is the following:

 

Basically, that 2 attributes are added to the main table with the names of the values of SimWaterBodies_FN, and with all values = <null> (This is not that critical, the value could be <empty>, 999, or other ...).

 

 

Thanks for the help.

Unless someone else replies, could you perhaps try rephrasing the question, I'm not sure I quite understand the issue. Perhaps even post a small sample workspace with a minimal dataset and describe what you'd like the output to be.


Unless someone else replies, could you perhaps try rephrasing the question, I'm not sure I quite understand the issue. Perhaps even post a small sample workspace with a minimal dataset and describe what you'd like the output to be.

Yes I am going to try to make it more clear with a simple example. Thanks David.


Well you can use @Value(SimWaterBodies_FN) in the AttributeManager (not AttributeCreator) and it will work. It won't expose the attribute, but you can see it in the Logger.

One additional problem (among many) is that you have two (or more?) attributes. So you would have to use a FeatureMerger/Joiner (match with a constant value so that all new attributes are added) to get all the new fields. But it would be *after* the AttributeManager, not before as you currently have it (maybe that's there for another reason).

Here's a sample workspace to show how it would work. The attribute xxxx records missing attributes (yyyy0, yyyy1, yyyy2). These are created and appended to the main set of data. The Logger shows that these are added to your five main features.

But the big issue is how to write this. You'll need to know what attributes are on the schema in advance else they won't get written - and if you knew that then you wouldn't need to go through the above process.

A dynamic workspace will get you so far, but again the schema has to exist somewhere. The only way I can see is to create the schema dynamically within the workspace. So you would need to create attribute{0}.fme_data_type = fme_varchar(40) (or whatever) and attribute{0}.name = Phosphate

Thinking about it, that's relatively straightforward. Just copy SimWaterBodies_FN to attribute{x}.name (maybe use an Aggregator to build up that list)

Anyway, unless I'm misunderstanding, I think that's the only way to do it.

The key is, if you know Phosphate and Ammonia are fields on the output, then you can just add them to the writer schema and get nulls. But if you don't know that, then you have to go through all of the above to get them on there.


Well you can use @Value(SimWaterBodies_FN) in the AttributeManager (not AttributeCreator) and it will work. It won't expose the attribute, but you can see it in the Logger.

One additional problem (among many) is that you have two (or more?) attributes. So you would have to use a FeatureMerger/Joiner (match with a constant value so that all new attributes are added) to get all the new fields. But it would be *after* the AttributeManager, not before as you currently have it (maybe that's there for another reason).

Here's a sample workspace to show how it would work. The attribute xxxx records missing attributes (yyyy0, yyyy1, yyyy2). These are created and appended to the main set of data. The Logger shows that these are added to your five main features.

But the big issue is how to write this. You'll need to know what attributes are on the schema in advance else they won't get written - and if you knew that then you wouldn't need to go through the above process.

A dynamic workspace will get you so far, but again the schema has to exist somewhere. The only way I can see is to create the schema dynamically within the workspace. So you would need to create attribute{0}.fme_data_type = fme_varchar(40) (or whatever) and attribute{0}.name = Phosphate

Thinking about it, that's relatively straightforward. Just copy SimWaterBodies_FN to attribute{x}.name (maybe use an Aggregator to build up that list)

Anyway, unless I'm misunderstanding, I think that's the only way to do it.

The key is, if you know Phosphate and Ammonia are fields on the output, then you can just add them to the writer schema and get nulls. But if you don't know that, then you have to go through all of the above to get them on there.

Thanks Mark. Very useful information. Your sample workspace was very clear too!


Reply