cancel
Showing results for 
Search instead for 
Did you mean: 

How to write an empty CSV file

mtran21
New Contributor III

I am looking for solution on how to write an empty data with headers csv file. I have a Oracle snap that execute a query then output to a csv file. I still want the csv file to be produced even the query returns zero record.
Here is my pipeline
image

2 REPLIES 2

dmiller
Former Employee

mtran21
New Contributor III

I am coming back here to share my simple solution how to write an empty CSV file when there is no data in the stream source (SQL or Oracle)

First, you need to do a COUNT query from your database. Then add a router, if COUNT is not equal zero, then do your thing, if COUNT is zero, then add a file Reader to read your empty CSV file that you put in your file directory, then write the file to your destination

So here is my entire pipeline
image

Then first snap is count
image

Then Router Snap
image

Then File Reader to read my empty CSV file with headers
image

Then finally, write that empty CSV file to destination
image

Hope that helps