Search code examples
azuredataflow

Dynamically Add a Timestamp To Files in Azure Data Flow


I've been working on a azure project, and I want to create a dataflow using a dynamic filename that contains timestamp. for example , if the output is a file name 'A' --> 'A_YY-mm-dd_hh_mm_ss' I already did that on a data factory using this link Here but in this case I don't know how could I use it. there is my data flow enter image description here

The input is an extract file( i did it with a copy data)


Solution

  • You can refer this code. I tried to modify the filenamePrefixForWindow method and I was able to achieve this. These were the changes I made -

    public String filenamePrefixForWindow(IntervalWindow window) {
            Calendar calendar = Calendar.getInstance();
            String year = String.valueOf(calendar.get(Calendar.YEAR));
            String month = String.format("%02d",(calendar.get(Calendar.MONTH)+1));
            String date = String.format("%02d",calendar.get(Calendar.DATE));
            int hh = calendar.get(Calendar.HOUR);
            String hour = String.format("%02d",(calendar.get(Calendar.AM_PM) == 0) ? hh:hh+12);
            String minute = String.format("%02d",calendar.get(Calendar.MINUTE));
            String full_date = year+"-"+month+"-"+date+"-"+hour+"-"+minute;
            String prefix =
                    baseFilename.isDirectory() ? "" : baseFilename.getFilename();
            return String.format(
                    "%s/%s/%s/%s/%s/output-%s", prefix,year,month,date,hour,full_date);
        }