Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
PawelJanus
Contributor
Contributor

Generate empty csv file with header

Hi,

I am unable to create an empty CSV file with a header. If there is no data, it generates an empty file without headers. I need a CSV file that contains only the header without any data. The 'Don't generate empty file' option is unchecked. 'Include header' is checked. If there is no data, the file is empty and with no header.

Labels (3)
2 Replies
Anonymous
Not applicable

Hi

There is no option on tFileOutputDelimited to create a empty file with header. As a workaround, store the data into memory using tHashOutput, write the header to a new file first, then read the data from memory and write them into the new file if there exist data. eg:

tFixedFlowInput--main--tFileOutputDelimited_1

|onsubjobok

tFileInputDeimited--main--tHashOutput_1

|runIf

tHashInput--main--tFileOutputDelimited_2

 

tFixedFlowInput: generate header value.

tFileOutputDelimited_1: create a new file and writhe the header.

 

set the condition of runIf as:

((Integer)globalMap.get("tHashOutput_1_NB_LINE"))>0

 

Regards

Shong

 

konvertilo
Partner - Contributor III
Partner - Contributor III

If the header is always the same for this file, why don't you create the CSV file with the header only ?

at the end of your job, you could just "cat" the header and the data.

if no data, then the header will be the first and unique row of the file.

if there are some data, you will get the header and the data below.