Post a reply

Write your message and submit

Options

Click in the dark area of the image to send your post.

Go back

Topic review (newest first)

tchd
2010-11-19 09:25:48

Hi Gabor,

It was a comment on the java code that I wrote that uses java.lang.reflection to test the field types and then enclose the strings. i.e. it has to be in the tJavaRow component to work.

Regards,
Rick

CaptainRoo
2010-11-19 03:56:27

Told you so. ;-)

Rick - aka tchd - why are you saying that it has to be tJavaRow? ODN did not specify that...

ODN
2010-11-17 11:32:07

Hello

I tried with the component "tFileOutputDeleimited "with the option "text enclosure"

with Integer as I get "123".

archenroot
2010-11-14 23:36:11

Well I edited this topic, because for the first time I was little bit wrong :-)) hehe

I checked tFileInputDelimited and you are able to use "Text enclosure" feature if you check the CSV option on component. So your functionality is already there.

This is also available by creating metadata for delimited file, select type CSV and there already is that option related to "Text-enclousure" as """, then the schema will be based on reading that file in a way:
"alfa" will be String
245 will be Integer

So Talend is already ready for your scenario.

Best regards,

archenroot

tchd
2010-11-04 12:55:33

CaptainRoo wrote:

This is all good, but the actual question is that the component should not even place "s around non string columns...
I would consider the behavior not correct, since an integer is non-text.

Hi CaptainRoo,

The code does only enclose strings, however I did neglect to state that:

- It should be in a tJavaRow
- You will need to include java.lang.reflection.*
- You will need to ensure that the tOutputFileDelimited has csv options turned off, so that no automatic enclosure is performed.


janhess: you are absolutely correct.  This method would add an overhead in processing due to the need to loop through the fields for every row, whereas adding a rule for each field wouldn't have that overhead.

Another option would be to create a code routine to add the "s and then apply it to each string field.


Regards,
Rick

janhess
2010-11-04 12:22:20

You could do it manually in a map rule by adding " to the start and end of string fields and not setting the csv options in the output file.
OK if there are only a few fields.

CaptainRoo
2010-11-04 00:19:25

This is all good, but the actual question is that the component should not even place "s around non string columns...
I would consider the behavior not correct, since an integer is non-text.

tchd
2010-11-03 15:51:24

Hi ODN,

I hope you don't mind me hijacking the thread a little, but I really liked John's idea of using java.lang.reflect, so gave it a go myself (see code below).  I'm fairly new to java, so I'm not sure if this would be considered robust enough for say production use.

John, if you would do it differently or have any tips ideas regarding robustness/error checking etc then I'd love to capture your thoughts. 

Regards,
Rick

Class cls = Class.forName(input_row.getClass().getName());   
Class clsOut = Class.forName(output_row.getClass().getName()); 

Field fieldlist[] = cls.getDeclaredFields();
Field fieldlistOut[] = clsOut.getDeclaredFields();

for (int i = 0; i < fieldlist.length; i++) {
    Field fld = fieldlist[i];
    Field fldOut = fieldlistOut[i];
    int mod = fld.getModifiers();     
    if ( Modifier.toString(mod).equals("public")) {
        if ( fld.getType().getName().equals("java.lang.String") ) {
            fldOut.set(output_row, "\"" + fld.get(input_row) + "\"");
        } else {
            fldOut.set(output_row, fld.get(input_row));
        }
    }
}

JohnGarrettMartin
2010-11-03 14:14:01

in a tJavaRow you can use java.lang.reflect to retrieve the column types, enclose strings in quotes and then write them out to a file delimited with no text enclosure.

ODN
2010-11-03 09:58:05

Hello

I want to make a CSV file with a tFileOutputDelimited with text enclosure only for type "String" (not for number).

exemple:

     12;"text2";"text3";15
     45;"text4";"text25";12

how to do this?

Thanks

Eric

Board footer

Powered by FluxBB