Four Stars

the names of the colunms are numbers

Hi everyone,

 

I have a problem with the names of the columns. Indeed, I created a file delimited in the metadata section to be able to import via this schema data from a delimited files. 

The problem is that my header contain number as names of columns, example of header: name_col_one;name_col_two;2010;2011.

Therefore, at the end of the creation of the metadata, when I choose the option 'Set heading row as column names', I have a '_', for example name_col_one;name_col_two;_010;'_011.

 

I really need to have a correct name of column because the next step is to unpivot my table and I don't want to have this kind of record name_col_one;name_col_two;_010;'value1_from_2010

name_col_one;name_col_two;_010;'value2_from_2010

 

but I want:

name_col_one;name_col_two;2010;'value1_from_2010

name_col_one;name_col_two;2010;'value2_from_2010

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars TRF
Twelve Stars

Re: the names of the colunms are numbers

To have a new header, just define it in a tMap and map columns from old schema manually.

TRF
6 REPLIES
Four Stars

Re: the names of the colunms are numbers

I forgot to say that I have more than one hundred columns, therefore, I cannot use a replace function in the tmap to change the '_' by '2'
Twelve Stars TRF
Twelve Stars

Re: the names of the colunms are numbers

Having column names starting by number is forbiden because of Java (see namming rules)

TRF
Four Stars

Re: the names of the colunms are numbers

Hi,

 

Thank you for your reply.

So, I cannot do anything?

 

I thought about something but I don't know if I can do it (I'm a beginner in Talend)

 

 

It is possible to add "manually" a header to use a Treplace component?

 

For example, after my unpivot, I have these records:

value1_from_column_one;value1_from_column_two;_010;'value1_from_2010

value2_from_column_one;value2_from_column_two;_010;'value2_from_2010

 

I add the "new" header to have this structure:

new_column_one; new_column_two;year;value

value1_from_column_one;value1_from_column_two;_010;'value1_from_2010

value2_from_column_one;value2_from_column_two;_010;'value2_from_2010

 

And after that, I use the Treplace component on the field "year" to replace all '_' by '2'.

 

The question is: How to add the new header?

 

Thank you very much in advance

 

 

Twelve Stars TRF
Twelve Stars

Re: the names of the colunms are numbers

To have a new header, just define it in a tMap and map columns from old schema manually.

TRF
Highlighted
Ten Stars

Re: the names of the colunms are numbers

I have several use cases where the output header format is not allowed by Java constraints.  You can write out the header first, then append your results to the same file.

Four Stars

Re: the names of the colunms are numbers

Hi again,

 

Thank you, it's works with the Tmap. I used the function StringHandling.CHANGE in my "new" header, which has been created in the Tmap as suggested.

 

Thank you again