How to make this step fail

King Java 790 Reputation points
2023-07-17T22:57:37.4066667+00:00

I am trying to send out email notification when there is no file inside designated Azure File Share location.

This was my original logic, but it does not appear to be doing what I expected ADF to be doing.

Even when there is no file with criteria, the first step (Copy data) still finished as successful.

User's image

How do I make the first step Fail if there is no data with what criteria indicated?

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

Accepted answer
  1. Subashri Vasudevan 11,231 Reputation points
    2023-07-18T03:57:58.6466667+00:00

    Hello @King Java

    If you are using a wildcard in the file name , even if there's no matching file, the copy activity will succeed. It is because , wild cards do not result in error when there's is no matching file.

    If you are specifically looking for a file, you can mention that file name in the data set, for example, abc.txt. If the copy activity doesn't find such file, if will fail. (This holds good when you parameterize the file name portion in the data set too)

    If you have to use a wild card in file name part, you can follow below steps.

    • Add a data set to be used with wildcard. In the dataset add a parameter called extension, which needs to be used in file name part. (my data set name is DelimitedText1)
    • Add get meta data activity and pass wild card name as follows pointing to the data set created in above step (Im passing *.txt to match any txt files in the ADLS, I am sure it can be used with File share too)Screenshot 2023-07-18 at 9.19.47 AM

    Next to get meta data activity, add an if condition to check the number of matching files brought by the get meta data activity. Please use the below expression in the if condition to check for files.

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

    This will evaluate to true if there are matching files, and false if there are no matching files. In the false part of if condition, add a fail activity and give message - File Not found and Error Code 404 (or anything). This will make sure to fail the pipeline if there are no files. Next to this activity you can connect your web activity to send notification.

    In the true part, you can have your copy activity.

    I had no .txt files in my data lake, so my pipeline failed. See below,

    Screenshot 2023-07-18 at 9.27.04 AM

    Hope it helps. Please let us know if you have questions.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.