You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Azure Data Factory阻止复制空文件?空文件处理疑问

Azure Data Factory: Handling Empty Files in Copy Activity

Hey there! Since you're new to ADF and working with Copy Activities, let's tackle your questions step by step.

What happens when Copy Activity encounters an empty file?

By default, Azure Data Factory does NOT trigger an error for empty files. The Copy Activity will run successfully, copy the empty file to your target destination, and you'll see in the activity logs that 0 rows were copied. The pipeline won't fail unless you specifically configure it to treat empty files as a failure scenario.

How to prevent Copy Activity from running on empty files

To block Copy Activity from executing when dealing with empty files, you'll need to add a pre-check using a combination of Get Metadata Activity and If Condition Activity. Here's a step-by-step breakdown:

Single File Scenario

  1. Add a Get Metadata Activity
    • Point it to your source file path.
    • In the "Field List" settings, select Size (this will fetch the file's size in bytes).
  2. Add an If Condition Activity
    • Connect it directly after the Get Metadata Activity.
    • Use this expression for the condition:
      @greater(activity('Get Metadata1').output.size, 0)
      
      (Replace Get Metadata1 with the actual name of your Get Metadata Activity)
  3. Configure your Copy Activity
    • Place your existing Copy Activity in the True branch of the If Condition.
    • Now, the Copy Activity will only run if the source file has a size greater than 0 (i.e., it's not empty). If the file is empty, the True branch skips execution, and the pipeline continues without failure.

Multiple Files Scenario (Folder with multiple files)

If you're processing a folder of files and want to skip empty ones individually:

  1. First, use a Get Metadata Activity to fetch the list of child items in your source folder (select Child Items in the Field List).
  2. Add a For Each Activity to loop through each child item from the Get Metadata output.
  3. Inside the For Each loop:
    • Add another Get Metadata Activity to fetch the Size of the current file (use the item() variable to reference the current file path).
    • Add an If Condition Activity with the same size-check expression as above.
    • Place your Copy Activity in the True branch to only copy non-empty files.

Optional: Fail the pipeline if an empty file is detected

If you want the pipeline to explicitly fail when an empty file is found instead of just skipping it, add a Fail Activity in the False branch of the If Condition. You can customize the error message to indicate an empty file was encountered.


内容的提问来源于stack exchange,提问作者Samyak Jain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 18:12:38