英文:
Azure Data Factory - How do I iterate and read records in a CSV file using a ForEach loop?
问题
我有一个要求,需要为数据集中的每一行生成一个唯一的“guid”,为此,我在复制活动中使用了一个额外的列,如下所示。
由于它为每一行生成相同的guid,我尝试使用查找并通过“For Each”循环进行迭代,如下所示。
在“For Each”循环中,我使用以下表达式来检索值:
@activity('Lookup1').output.value
然而,我遇到了这个错误:
这是查找活动的示例输出:我使用.csv文件作为源
{
"firstRow": {
"Bill-to Customer Name": "****",
"Bill-to Customer No_": "****",
// ... (其他字段)
"ProjectCustomer_FullName": "****",
"ProjectCustomer_ID": "****"
},
"effectiveIntegrationRuntime": "****",
"billingReference": {
"activityType": "****",
// ... (其他计费参考字段)
},
"durationInQueue": {
"integrationRuntimeQueue": ****
}
}
如何解决这个问题?感谢您的帮助。
英文:
I have a requirement to generate a unique 'guid' for each row in the dataverse, and for that, I'm using an additional column in the copy activity as shown below.
Since it generates the same guid for every row, I'm trying to use a lookup and iterate through a "For Each" loop as shown below.
In the "For Each" loop, I'm using this expression to retrieve the values:
@activity('Lookup1').output.value
However, I'm encountering this error:
This is a sample output from the lookup activity: I'm using .csv file as the source
{
"firstRow": {
"Bill-to Customer Name": "****",
"Bill-to Customer No_": "****",
// ... (other fields)
"ProjectCustomer_FullName": "****",
"ProjectCustomer_ID": "****"
},
"effectiveIntegrationRuntime": "****",
"billingReference": {
"activityType": "****",
// ... (other billing reference fields)
},
"durationInQueue": {
"integrationRuntimeQueue": ****
}
}
How to resolve this issue ? Appreciate your help on this.
答案1
得分: 0
请尝试一下:
@activity('Lookup1').output.firstRow.ProjectCustomer_ID
英文:
Can you please try
@activity('Lookup1').output.firstRow.ProjectCustomer_ID
答案2
得分: 0
要使用ForEach迭代CSV文件,您需要在查找中禁用“仅第一行”。当我在ForEach中使用表达式“@activity('Lookup1').output.value”而没有禁用查找中的“仅第一行”时,我遇到了相同的错误。
因为“仅第一行”将第一行CSV作为对象返回。
禁用它将从CSV中提取查找输出数组,您可以看到在禁用后,我的管道运行没有任何错误。
在ForEach中使用相同的“@activity('Lookup1').output.value”来使用查找输出数组。在ForEach内部,您可以通过“@item().<property_name>”或“@item()['<property_name>']”访问此数组的值。
英文:
To iterate the CSV file using ForEach, you need to Disable the First row only
in the lookup. I got same error, when I used expression @activity('Lookup1').output.value
in the ForEach without disabling the First row only
in the lookup.
Because, First row only
will give the First row of csv as the object.
Disabling it will give the Lookup output array from the csv and you can see My pipeline ran without any errors after disabling it.
Use the same @activity('Lookup1').output.value
in the ForEach to use the lookup output array. Inside ForEach, you can access this array values by @item().<property_name>
or @item()['<property_name>']
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论