ADF Get Metadata File Count in IF Condition

Jay 561 Reputation points
2021-06-03T11:40:18.303+00:00

Hi,

I have a Get Metatdata task and need to check if there are any files returned before moving on to next step.

I have an IF condition which triggers another pipeline with a for each in (as I can't have For Each in an IF Condition).

102068-image.png

As a test with a int variable set as 1 or 0 etc the IF Condition works OK but if I can't workout now how to get a simple count of the output files i.e. filecount > 0.

I have tried this from researching on the net but doesn't seem to work for me.

@if(empty(activity('GetFileNames').output.childItems),equals(2,1),greater(length(activity('GetFileNames').output.childItems),100))

This is Get Metadata output when there are files

102057-image.png

This is output when there are no files

102046-image.png

surely must be an easy built in way to do this...

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. MartinJaffer-MSFT 26,236 Reputation points
    2021-06-03T19:28:27.95+00:00

    Hello @Jay and welcome to Microsoft Q&A.

    The solution you came up with using the length() is the fastest and simplest way.

    However the expression itself could be refined.

    @greater( length(activity('GetFileNames').output.childItems), 0)  
    

    I wrote that freehand, so please let me know if I made a mistake. This compares whether the length of the childItems array is greater than 0. It should return true if greater than 0, false otherwise. We do not need to use the if and equals(2,3) because the greater function returns a true/false just like equals() does.

    In the case of no files, childItems is [] . [] is the empty array, an array with 0 items, so length([]) should return 0.

    Let me know if this helps.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jay 561 Reputation points
    2021-06-03T11:47:19.317+00:00

    Looks like this may work... any flaws in this or better way...
    @if(contains(activity('GetFileNames').output,'childitems'), length(activity('GetFileNames').output.childitems), equals(2,3))

    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.