简体   繁体   English

Azure ADF V2 ForEach File CopyData 从 Blob 存储到 SQL 表

[英]Azure ADF V2 ForEach File CopyData from Blob Storage to SQL Table

I need to design an ADF pipeline to copy a CSV file created on a particular Blob Store folder path named "Current" to a SQL table.我需要设计一个 ADF 管道,以将在名为“Current”的特定 Blob 存储文件夹路径上创建的 CSV 文件复制到 SQL 表。 After successful copy, i'll have to move the file to an archive folder.成功复制后,我必须将文件移动到存档文件夹。

Things i've accomplished : I'm using a Copy Data Activity that copies the CSV file and loads into my SQL table.我已经完成的事情: 我正在使用复制数据活动来复制 CSV 文件并加载到我的 SQL 表中。 On success, another copy data activity will copy the CSV file from "Current" folder to "Archive", after this i have a Delete activity that deletes the file from Current Folder.成功后,另一个复制数据活动会将 CSV 文件从“当前”文件夹复制到“存档”,此后我有一个删除活动从当前文件夹中删除文件。

Issue : This is totally fine where there is only one file at a time.问题:在一次只有一个文件的情况下这完全没问题 But i want redesign this to handle multiple files imports.但我想重新设计它以处理多个文件导入。 I want make use of ForEach activity.我想利用 ForEach 活动。 Please help.请帮忙。

You need to add a Get Metadata activity before the for-each.您需要在 for-each 之前添加一个 Get Metadata 活动。 The Get Metadata activity will get the files in the current directory and pass them to the For-Each. Get Metadata 活动将获取当前目录中的文件并将它们传递给 For-Each。 You connect it to your Blob storage folder and specify the file mask.将其连接到 Blob 存储文件夹并指定文件掩码。 The output of the activity will need to be the input for your for-each loop.活动的输出需要是 for-each 循环的输入。 Something like this..@activity('Get Metadata').output.像这样的东西..@activity('Get Metadata').output。 By the way how are you triggering this ADF pipeline?顺便说一下,你是如何触发这个 ADF 管道的? Another way to accomplish this would be to setup an event trigger to run this pipeline whenever a file is created in that blob directory.实现此目的的另一种方法是设置事件触发器以在该 blob 目录中创建文件时运行此管道。 Here are the steps to use the For-Each on files in a storage container.以下是对存储容器中的文件使用 For-Each 的步骤。

  1. Set the Get Metadata argument to "Child Items"将获取元数据参数设置为“子项” child_items-截图
  2. In your For-Each set the Items to @activity('Get Metadata1').output.childitems在您的 For-Each 中,将 Items 设置为 @activity('Get Metadata1').output.childitems

对于每个图像

  1. In the Source Dataset used in your Copy Activity create a parameter named FileName.在复制活动中使用的源数据集中,创建一个名为 FileName 的参数。

文件名参数

  1. Set the file path to use the parameter设置文件路径使用参数文件路径参数

  2. On the Copy Activity set the FileName parameter to @item().name在 Copy Activity 上将 FileName 参数设置为 @item().name 在此处输入图片说明

To finish you'll need to set the sink to whatever you need.要完成,您需要将水槽设置为您需要的任何位置。 That should do it.那应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM