Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Gurus,
Talend converts null values into empty strings when we configure the tFileOutputDelimited to write the data with text enclosures . Say , if integer column is having null values, when I write this integer column into csv file using tFileOutputDelimited with csv options enabled.
null value in the integer turns into "". empty string..
tFileOutputDelimited compontent is enclosing the numeric columns within double quotes. which is wrong.
For example below is source data, when we transform the json data into csv with text enclosures (age is integer column)
[
{
"name" : "john",
"age":22,
"city":"London"
},
{
"name" : "leon",
"age": null ,
"city":"Brighton"
}
]
Expected output in csv :
name,age,city
"John",22,"Lonon"
"leon",,"Brighton
Actual Output in talend is:
name,age,city
"John","22","Lonon"
"leon","","Brighton -------------> here null value in the force is converted to empty string.
How to resolve this use ?
hello
There is no an option on tFileOutputDelimted to fix this issue directly, a workaround is:
create a temporary file, then read this temporary as a string using tFileInputRaw and replace the double quotes with empty value on a tJavaRow, and output the string a CSV file using tFIleOutputRaw.
Regards
Shong
Hi Shong,
This fix won't work always.
[
{
"name" : "john",
"age":22,
"city":"London",
"country": "UK"
},
{
"name" : "leon",
"age": null ,
"city":"Brighton",
"country":""
}
]
Data from upstream is sending the empty string for some of the string columns . This fix will convert the empty string to null.
Talend should include a option in the tFileOutput delimiter on treating the null values. "Don't enclose null values within field enclosures".
try this:
output_row.content = input_row.content.toString().replaceAll("\"\"","null");