One Star

Empty File Validation in Talend ETL

Hi,
I'm using Talend ETL for my files processing. I had a requirement where I need to identify whether input file is empty or not. I'm aware we can get the file properties and check the size is 0 or not.
But my problem is after tFileList Component what are the components I have to add to identify the empty file.
if it is empty file it should go to one flow - else it has to go normal processing flow.
Can you please help me for the above problem.
Kalyan M
9 REPLIES
Community Manager

Re: Empty File Validation in Talend ETL

Hi
In Talend, you can use tFileProperties to get the file properties, there is a field called size that populate the file size, if it is 0, means the file is empty. According to your description, a job design for example looks like:
tFileFlist--iterate--tFileProperties--tJavaRow--runIf_1-->normal processing flow
--runIf_2--->another processing if the file is empty
on tJavaRow, check the file if it is empty and put the result to a global variable, for example:
if(input_row.size==0){
globalMap.put("isEmpty", true);
}else{
globalMap.put("isEmpty", false);
}

set the condition of runIf_1 as:
!(Boolean)globalMap.get("isEmpty")
set the condition of runIf_2 as:
(Boolean)globalMap.get("isEmpty")
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Five Stars

Re: Empty File Validation in Talend ETL

It can be achieve using two way and here are they..
1. tFileList---iterate--tFileInput
in tFileInput components basic property check skip empty record check box this is one way.
2.. tFileList---tFileProperty-----if(has siz)-----1
\
\
if (file has zero size)----------2
Hope this will help
One Star

Re: Empty File Validation in Talend ETL

Thanks for the response.
I'm done with the flow but in the last step I got struck
tFileList -> tFileProperties -> If empty file means it has to connect to tMap component and populate few fields related to error handling.
If it is not empty file it has to connect to tFileInputDelimited which I'm able to do it.
Can you help me in connecting from tFileProperties --> tMap component
One Star

Re: Empty File Validation in Talend ETL

Hi Shong
I tried to implement your approach but getting the below exception
Exception in component tJavaRow_1
java.lang.NullPointerException
at finance_coda.jo_coda_0010_processv11_ecommerce_0_1.jo_CODA_0010_ProcessV11_ECOMMERCE.tFileList_1Process(jo_CODA_0010_ProcessV11_ECOMMERCE.java:4210)
at ...............
I'm not able to paste the screen shot but my implementation is as follows -
tFileFlist--iterate--tMessage--iterate--tFileProperties--main--tJavaRow--runIf_1-->tJava--tMap-- ...
--runIf_2--->another processing if the file is empty
I have placed the if conditions and javaRow code as said by you.
One Star

Re: Empty File Validation in Talend ETL

Thanks All. I resolved the issue, it's working.
One Star

Re: Empty File Validation in Talend ETL

Hi Chakri,
How have you resolved the null pointer exception
One Star

Re: Empty File Validation in Talend ETL

Hi Team ,
I m getting below error
"Syntax error on token "(", Expression expected after this token"
ok_Hash.put("tFileExist_1", true);
end_Hash.put("tFileExist_1", System.currentTimeMillis());
if () {
if(execStat){
runStat.updateStatOnConnection("If1", 0, "true");
}
tMsgBox_1Process(globalMap);
}
else{
if(execStat){
runStat.updateStatOnConnection("If1", 0, "false")}
          }
/*
I need to check whether file exist or not ? ..If condition is not working ,...
Community Manager

Re: Empty File Validation in Talend ETL

Hi mohini 
It is a compilation error here, you must have a syntax error in the Java code you written on the component such as tJavaRow component if you follows the case. Please open the component properties of tJavaRow and check the Java code.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Empty File Validation in Talend ETL

Hi Shung,
Yes ur right I was missing if condition .... which we will get it when we click on if (when we are using Run if, double click on If )there we .... there we need to provide condition
ex:((Boolean)globalMap.get("tFileExist_1_EXISTS"))==true or
OR
 false ....
THanks for the help
Regards
Mohini