Skip to main content
Dear community,

 

 

is there a way how I can set a data type (integer, char, float, ...) in a transformer?

 

 

Usually I create the data type in the Feature Type Properties menu of the Writer. On some occassion, it would be helpfull if I could set the types manuelly in a transformer, so that the writer recognizes the formats automatically.

 

 

I do not want to tell every writer which format it has to be. We can of course tell a single writer all the data types and then copy the attributes from one Writer to another. This one should work.

 

 

But can I set the data type to a specific type in a transformer before I write the data out?

 

 

Thank you very much for your help.

 

 

Kind regards,

 

ThomasK

 

 

Hi,

 

 

this is not really possible (without dirty hacks, see my Python code here) due to the way FME works internally.

 

 

Also, to me it seems a bit dubious to assume that the first feature that enters the writer can properly describe all the following features. E.g. what happens if the first feature contains an integer for attribute A, whereas the next feature contains a string in attribute A?

 

 

My opinion is that explicit is better than implicit, so I'd recommend configuring the writer with set datatypes rather than relying on the first feature to define the schema.

 

 

David
Hi David,

 

 

thank you very much for your response.

 

 

The writer should not recognize the data types by the first feature that enters it, but by the definitions made by the user in a (possible not existing) transformer before the writer. A colleague of mine wants to define these data types in a transformer (or preferably directly in the PythoCaller, but I guess that's not possible, is it?), rather than to do it in the writers menu.

 

 

I once's read an article about how the data types are stored in the FME but could't find it anymore. I guess it was in the FMEpedia. If someone has information about it, it would also be helpful.

 

 

Kind regards

 

ThomasK
Hi Thomas,

 

 

> how the data types are stored in the FME

 

 

This documentation is describing that "FME stores all attributes as character strings ...".

 

 

Takashi
Hi @thomask, I have the same need, since I read dgnV8 which delivers texts string(200) and want to write them to spatialLite database, which I configured to write string(20). However, it refuses to do so and writes instead string(200). Trying to find an answer...

On the other hand, it seems you're looking for a dynamic setup using advanced schema contructing. Here is good starting documentation: https://knowledge.safe.com/articles/43899/dynamic-workflows-advanced-example-modifying-the-s.html and https://s3.amazonaws.com/gitbook/Desktop-Advanced-2016/DesktopAdvanced4AdvancedRW/4.15.AdvancedDynamicSchemas.html

You will have to use a dynamic feature type on the reader, and "Schema from first Feature" as schemasource. Using for example an AttributeCreator you can define your attribute types in the attribute{}.fme_data_type and attribute{}.name array and write them to the dynamic writer, which write the correct data types.

That wouldn't fix my problem, however, that seems to be fixed in fme 2017.


Desparately looking for an answer I discovered the solution was right under my nose: simply use an AttributeManager as the first transformer from a Reader.

 

With action set to "Set value" in the "Attribute Value" field you can use the Math functions to set the desired data type. For example:

@double(@Value(temperature)) 

You can even change the data type and rename an attribute at the same time by setting action to "Rename" and then use the new attribute name in the "Attribute Value" field.


Reply