gpt4 book ai didi

azure - 为什么 Foreach 循环内的 SetVariable 未按 Azure 数据工厂中的预期进行迭代

转载 作者:行者123 更新时间:2023-12-03 06:09:36 28 4
gpt4 key购买 nike

我的数据文件夹位于本地,其中包含子文件夹。每个子文件夹的名称中都有一个日期,并且内部可以包含多个 Excel 文件。

enter image description here

ForEach 事件迭代每个子文件夹名称并将每个 Excel 中的数据加载到 SQL 表中。

设置变量1仅从子文件夹名称中提取数据部分的子字符串设置变量2只需将点(日期中的)替换为“/”

问题是,为什么结果sql表只包含5-31-2023日期? 2023 年 6 月 30 日发生了什么?

enter image description here

SetVariable2 具有变量 DatePart 的表达式。

@子字符串(项目名, 添加(lastIndexOf(item().name, ' '), 1), sub(length(item().name), add(lastIndexOf(item().name, ' '),1)))

接下来,我在复制数据事件中使用变量 DatePart 作为新列。

enter image description here

sql表的结果:

![enter image description here

更新:

使用@RakeshGovindula方式重建管道。那么为什么以他的方式执行的顺序会发生它应该发生的情况

enter image description here

但是,在我的例子中,执行顺序是不正确的。一切都是一样的,连表情都一样。

enter image description here

最佳答案

我尝试了你的方案,它对我来说效果很好。

这些是我的文件夹,为了简单演示,我在这两个文件夹中使用了相同的文件名 mycsv2.csv

enter image description here

我会将这 2 个 CSV 中的数据插入到单个 SQL 表中,其中附加列如下。

将获取元数据子项提供给 ForEach 后,在 ForEach 内部,使用以下表达式从 @item().name 获取日期部分(使用 /) .

@replace(split(item().name,' ')[1],'.','/')

enter image description here

并给出相同的附加列。

enter image description here

Datepart 将在每次迭代中给出这样的结果。

enter image description here

SQL表中的结果数据:

enter image description here

此外,当您在每次迭代中将每个文件中的数据插入到 SQL 表中时,请确保在 ForEach 中启用顺序检查。

这是我的管道 JSON 供您引用:

{
"name": "pipeline1",
"properties": {
"activities": [
{
"name": "Get Metadata1",
"type": "GetMetadata",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"dataset": {
"referenceName": "sourcefiles",
"type": "DatasetReference"
},
"fieldList": [
"childItems"
],
"storeSettings": {
"type": "AzureBlobFSReadSettings",
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
}
},
{
"name": "ForEach1",
"type": "ForEach",
"dependsOn": [
{
"activity": "Get Metadata1",
"dependencyConditions": [
"Succeeded"
]
}
],
"userProperties": [],
"typeProperties": {
"items": {
"value": "@activity('Get Metadata1').output.childItems",
"type": "Expression"
},
"isSequential": true,
"activities": [
{
"name": "Get Metadata2",
"type": "GetMetadata",
"dependsOn": [],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"dataset": {
"referenceName": "subfolders_getmetadata",
"type": "DatasetReference",
"parameters": {
"foldername": {
"value": "@item().name",
"type": "Expression"
}
}
},
"fieldList": [
"childItems"
],
"storeSettings": {
"type": "AzureBlobFSReadSettings",
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
}
},
{
"name": "split and replace with slash",
"type": "SetVariable",
"dependsOn": [
{
"activity": "Get Metadata2",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"variableName": "Datepart",
"value": {
"value": "@replace(split(item().name,' ')[1],'.','/')",
"type": "Expression"
}
}
},
{
"name": "Copy data1",
"type": "Copy",
"dependsOn": [
{
"activity": "split and replace with slash",
"dependencyConditions": [
"Succeeded"
]
}
],
"policy": {
"timeout": "0.12:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"additionalColumns": [
{
"name": "ItemName",
"value": {
"value": "@item().name",
"type": "Expression"
}
},
{
"name": "FileDatevariable",
"value": {
"value": "@variables('Datepart')",
"type": "Expression"
}
}
],
"storeSettings": {
"type": "AzureBlobFSReadSettings",
"recursive": true,
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "AzureSqlSink",
"writeBehavior": "insert",
"sqlWriterUseTableLock": false,
"tableOption": "autoCreate",
"disableMetricsCollection": false
},
"enableStaging": false,
"translator": {
"type": "TabularTranslator",
"typeConversion": true,
"typeConversionSettings": {
"allowDataTruncation": true,
"treatBooleanAsNumber": false
}
}
},
"inputs": [
{
"referenceName": "csvfile",
"type": "DatasetReference",
"parameters": {
"foldername": {
"value": "@item().name",
"type": "Expression"
}
}
}
],
"outputs": [
{
"referenceName": "AzureSqlTable1",
"type": "DatasetReference",
"parameters": {
"tablename": {
"value": "@split(item().name,' ')[0]",
"type": "Expression"
}
}
}
]
}
]
}
}
],
"variables": {
"Datepart": {
"type": "String"
}
},
"annotations": []
}
}

关于azure - 为什么 Foreach 循环内的 SetVariable 未按 Azure 数据工厂中的预期进行迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76948387/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com