question

Jay-8106 avatar image
0 Votes"
Jay-8106 asked MartinJaffer-MSFT commented

ADF Get Metadata File Count in IF Condition

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
image.png (10.8 KiB)
image.png (25.7 KiB)
image.png (15.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MartinJaffer-MSFT avatar image
0 Votes"
MartinJaffer-MSFT answered MartinJaffer-MSFT commented

Hello @Jay-8106 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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes that line worked and easier to read than the one I had, Thanks.

0 Votes 0 ·

Great! Thanks for letting me know it worked well for you. Have a great weekend @Jay-8106 .

0 Votes 0 ·
Jay-8106 avatar image
1 Vote"
Jay-8106 answered MartinJaffer-MSFT converted comment to answer

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))

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.