Writing zeros for all columns in csv file based on a specific condition in ADF

sachin gupta 376 Reputation points
2021-10-28T23:18:19.247+00:00

Hello,

I am calling a LinkedIn endpoint using REST activity in ADF. Below are the 2 things which I am working on

Scenario 1:

JSON Response:

{
    element:
        [
          count:0
        ]
}

For the above given response, I need to write the value 0 for all the 3 columns which I have in CSV.

Scenario 2:

JSON Response:

{
    element:
        [
          Clicks:70,
          Impressions:234,
          Likes:20
        ]
}

For above response all the values will go to the corresponding columns in CSV -> This scenario is working as it is straight forward, but for the first scenario, as the result is zero, nothing is getting written in CSV. I want that for such cases all the column should have the 0 value.

Please guide me on this issue.

Thanks,
Sachin

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,603 questions
{count} votes

1 answer

Sort by: Most helpful
  1. svijay-MSFT 5,201 Reputation points Microsoft Employee
    2021-11-01T13:13:51.387+00:00

    Hello @sachin gupta ,

    Thanks for getting back. My apologies for not being clear. My ask was more related by what are you making performing this data movement like - Copy Activity or the mapping data flow.

    Option 1 : Using Copy Activity

    NOTE : The working of the approach depends on how the data is returned. If the copy activity is triggered copies only one row of data i.e. meaning it either returns Scenario 1 or Scenario 2 as per the question (not multiple rows).

    145483-image.png

    Then you can have a Web Activity first. You can access the response by following the below:

    activity('Web1').output.response  
    

    You could do a condition - Check the response of a web activity. Based on the response, you could have a copy activity defined with the If activity (True - False)

    Option 2 :

    You could make use of the Mapping Data flow. You could do transformation - like having derived column transformation upon the source and store the manipulated values.

    You could check whether there is count and if there is '0'. Then update the value of the other column - for instance clicks as 0 - else - update the value of the clicks as a source. You could repeat the same for other columns.

    145524-image.png