Skip to main content

Hi Community,

I need to extract a CSV Style content from a SQL field of an SQL table.

It is stored into a single field.

The content looks like this:

Classification,Fonction
03-1,300
03-2,301
AA-10,C-1000
AA-12,C-1000
AA-15,C-1000
AA-17,C-1000
AA-20,C-1000
AA-22,C-1000
AA-25,C-1000
AA-27,C-1000
AA-30,C-1000

As you can see, the first line gives me the Attributes names and the following lines gives me the values

What would be the best way to turn this into multiple features using the first line as the Attributes names ?

Thank you

One way to do this:

  • Explode lines to features by newline.
  • Explode the attributes to features by comma.
  • Split header and data.
  • Merge headers to data.
  • Create attributes from headers and data.
  • Merge back into lines.
  • Expose created attributes.

Yes, you need to expose the attributes. No this can not be done dynamic. :-)

The only dynamic thing you can do is to create a schema feature using the SchemaScanner to write the result with dynamic generated attributenames.


Solution without a featureMerger:


One way to do this:

  • Explode lines to features by newline.
  • Explode the attributes to features by comma.
  • Split header and data.
  • Merge headers to data.
  • Create attributes from headers and data.
  • Merge back into lines.
  • Expose created attributes.

Yes, you need to expose the attributes. No this can not be done dynamic. :-)

The only dynamic thing you can do is to create a schema feature using the SchemaScanner to write the result with dynamic generated attributenames.

Great ! Thank you ! 

For now, I can manually expose the attributes. I will give a try with the SchemaScanner for sure !


Solution without a featureMerger:

Hi, @jkr_wrk , 

The concept looks interesting, but I can’t figure out what your “AttributeSplitter_3” is doing. What would be the parameters ?

and how do you link the link the header with the data after ?

Thank you


I thought AttributeSplitter_3 was simple but after a second look I see I had to puzzle that myself as well.

It creates the _list_headers{} from the _list{0} . This _list_headers{} is used in AttributeCreator_3 to make it the AttributeName. This is a bit tricky because you put @Value(_list_headers{@Value(_element_index}}) in the AttributeName field.

_element_index is the index of the AttributeSplitter_2 which splitted the value.

 


I thought AttributeSplitter_3 was simple but after a second look I see I had to puzzle that myself as well.

It creates the _list_headers{} from the _list{0} . This _list_headers{} is used in AttributeCreator_3 to make it the AttributeName. This is a bit tricky because you put @Value(_list_headers{@Value(_element_index}}) in the AttributeName field.

_element_index is the index of the AttributeSplitter_2 which splitted the value.

 

OMG ! thank you @jkr_wrk for the explantation, I was not able to figure out by myself !


Reply