Question

transform row values ??to column attribute

  • 29 October 2019
  • 9 replies
  • 76 views

Badge

Hello

 

I am looking to perform the following operation :

 

- transform the value of my column into a column attribute.

 

 

table A ==> table B

 

colA val1 val2 val3 (that's my new columns)

 

val1

 

val2

 

val3

 

 

How to do it simply?

 

With which transformer ? (actually to my mind I guess it's the opposite of transpose transformer)

I know the AttributeCreator but these parameters are static (I dont want to fill all the fields)

 

thank you

9 replies

Badge +16

Hi @jerome,

Have a look at the AttributeExploder transformer.

Hope this helps,

Itay

Badge

Hi @jerome,

Have a look at the AttributeExploder transformer.

Hope this helps,

Itay

Yes you're right. This transformer creates new records.

But I may have misspoke myself. I'm trying to automate the creation of attribute without writting the value in AttributeCreator.

Badge +3

@jerome

 

 

Maybe this can inspire ?:

https://knowledge.safe.com/storage/attachments/31115-31082-dynamci-key-kwak.fmw

 

You would have to replace the exposer and have schema creation, extraxtion or dynamic schemamaapping .

Userlevel 2
Badge +17

Hi @jerome,

When reading from table A, each row will be a separate feature. You can rename the value for each row to a distinct attribute name, then use an Aggregator to joins the rows into a single feature:

- If there is no row number on the features, create one with a Counter

- Use an AttributeCreator to create a unique column name attributeI ie. col_name) from the _count value (ie. col_@Value(_count)).

- Use a second AttributeCreator to create an attribute with name set to @Value(col_name) and value set to row value

- Use an Aggregator to aggregate all the rows into a single feature. Set Accumulation mode to Merge Incoming Attributes to get all the new column attributes added.

- You may need to add an AttributeExposer to expose these new attributes

I am attaching a simple workspace to illustrate the process.

 

mergerows.fmw
Badge

Hi @jerome,

When reading from table A, each row will be a separate feature. You can rename the value for each row to a distinct attribute name, then use an Aggregator to joins the rows into a single feature:

- If there is no row number on the features, create one with a Counter

- Use an AttributeCreator to create a unique column name attributeI ie. col_name) from the _count value (ie. col_@Value(_count)).

- Use a second AttributeCreator to create an attribute with name set to @Value(col_name) and value set to row value

- Use an Aggregator to aggregate all the rows into a single feature. Set Accumulation mode to Merge Incoming Attributes to get all the new column attributes added.

- You may need to add an AttributeExposer to expose these new attributes

I am attaching a simple workspace to illustrate the process.

 

mergerows.fmw

This is exactly what I was looking for. But I don't understand very well how it works with the first AttributeCreator.

How is it possible to create an attribute list with a single attribute definition?

Badge

@jerome

 

 

Maybe this can inspire ?:

https://knowledge.safe.com/storage/attachments/31115-31082-dynamci-key-kwak.fmw

 

You would have to replace the exposer and have schema creation, extraxtion or dynamic schemamaapping .

Thanks . It seems to be a complete solution. I m going to test it now.

Badge

Well I have made good progress ... but

Can we automate attribute import in attributeExposer?

 

Or how to fill a lot of attribute without any re-entry ?
Userlevel 2
Badge +17

Well I have made good progress ... but

Can we automate attribute import in attributeExposer?

 

Or how to fill a lot of attribute without any re-entry ?

That is a tricky one, since the attribute names are not known until runtime. If the names will be constant over different datasets, I use the following technique to mostly automate populating the AttributeExposer:

- Connect an AttributeExploder to the Aggregator output.

- Add a CSV writer to the workspace, then connect the output feature type to the AttributeExploder output. Only output the attribute 'attr_name'.

- Run the workspace to create the CSV file.

- Remove the AttributeExploder and CSV writer.

- Connect an AttributeExposer to the Aggregator output. Open the parameters, then click the Import button.

- Import form the CSV file you just created, using the CSV reader, and choosing to import Attribute Values instead of the default Attribute Names.

If the attributes will not be constant, you can try using the a combination of the FME Hub SchemaSetter transformer and using Dynamic mode on the writer.

Badge

Well I have made good progress ... but

Can we automate attribute import in attributeExposer?

 

Or how to fill a lot of attribute without any re-entry ?

Great !

 

That's a complete process you describe here.

 

I will note it immediately

 

But how do you know what object is known or not at runtime process ?

 

Do you know if exists runtime step option ?

Reply