如何让 Azure 数据工厂循环访问文件夹中的文件
How to get Azure Data Factory to Loop Through Files in a Folder
我在看下面的link
我们应该能够在文件夹路径和文件名中使用通配符。如果我们单击 'Activity' 并单击 'Source',我们将看到此视图。
我想循环浏览几个月的任何一天,所以它应该是这样的视图。
当然这实际上行不通。我收到以下错误:ErrorCode:'PathNotFound'。消息:'The specified path does not exist.'。给定文件路径和文件名中的特定字符串模式,我如何才能获得递归遍历所有文件夹中所有文件的工具?谢谢
I would like to loop through months any days
- 为此,您可以将两个参数从您的管道传递给 activity,以便可以根据这些参数动态构建路径。 ADF V2 允许您传递参数。
让我们开始一个一个的过程:
1。创建一个管道并在其中为您的月份和日期传递两个参数。
注意:如果需要,也可以从其他活动的输出中传递此参数。参考:Parameters in ADF
2。创建两个数据集。
2.1 接收器数据集 - 此处为 Blob 存储。 Link 它与您的 Linked 服务并提供容器名称(确保它存在)。同样,如果需要,它可以作为参数传递。
2.2 源数据集 - Blob 存储再次出现或根据您的需要而定。 Link 它与您的 Linked 服务并提供容器名称(确保它存在)。同样,如果需要,它可以作为参数传递。
注:
1、文件夹路径决定复制数据的路径。如果容器不存在,activity 将为您创建,如果文件已经存在,默认情况下将覆盖该文件。
2. 如果要动态构建输出路径,则传递数据集中的参数。在这里,我为名为 monthcopy 和 datacopy 的数据集创建了两个参数。
3。在管道中创建副本 Activity。
通配符文件夹路径:
@{concat(formatDateTime(adddays(utcnow(),-1),'yyyy'),'/',string(pipeline().parameters.month),'/',string(pipeline().parameters.day),'/*')}
where:
The path will become as: current-yyyy/month-passed/day-passed/* (the * will take any folder on one level)
测试结果:
JSON 管道模板:
{
"name": "pipeline2",
"properties": {
"activities": [
{
"name": "Copy Data1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": true,
"wildcardFolderPath": {
"value": "@{concat(formatDateTime(adddays(utcnow(),-1),'yyyy'),'/',string(pipeline().parameters.month),'/',string(pipeline().parameters.day),'/*')}",
"type": "Expression"
},
"wildcardFileName": "*.csv",
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "DelimitedTextSink",
"storeSettings": {
"type": "AzureBlobStorageWriteSettings"
},
"formatSettings": {
"type": "DelimitedTextWriteSettings",
"quoteAllText": true,
"fileExtension": ".csv"
}
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "DelimitedText1",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "DelimitedText2",
"type": "DatasetReference",
"parameters": {
"monthcopy": {
"value": "@pipeline().parameters.month",
"type": "Expression"
},
"datacopy": {
"value": "@pipeline().parameters.day",
"type": "Expression"
}
}
}
]
}
],
"parameters": {
"month": {
"type": "string"
},
"day": {
"type": "string"
}
},
"annotations": []
}
}
JSON SINK 数据集模板:
{
"name": "DelimitedText1",
"properties": {
"linkedServiceName": {
"referenceName": "AzureBlobStorage1",
"type": "LinkedServiceReference"
},
"annotations": [],
"type": "DelimitedText",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"container": "corpdata"
},
"columnDelimiter": ",",
"escapeChar": "\",
"quoteChar": "\""
},
"schema": []
}
}
JSON 源数据集模板:
{
"name": "DelimitedText2",
"properties": {
"linkedServiceName": {
"referenceName": "AzureBlobStorage1",
"type": "LinkedServiceReference"
},
"parameters": {
"monthcopy": {
"type": "string"
},
"datacopy": {
"type": "string"
}
},
"annotations": [],
"type": "DelimitedText",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"folderPath": {
"value": "@concat(formatDateTime(adddays(utcnow(),-1),'yyyy'),dataset().monthcopy,'/',dataset().datacopy)",
"type": "Expression"
},
"container": "copycorpdata"
},
"columnDelimiter": ",",
"escapeChar": "\",
"quoteChar": "\""
},
"schema": []
}
}
我在看下面的link
我们应该能够在文件夹路径和文件名中使用通配符。如果我们单击 'Activity' 并单击 'Source',我们将看到此视图。
我想循环浏览几个月的任何一天,所以它应该是这样的视图。
当然这实际上行不通。我收到以下错误:ErrorCode:'PathNotFound'。消息:'The specified path does not exist.'。给定文件路径和文件名中的特定字符串模式,我如何才能获得递归遍历所有文件夹中所有文件的工具?谢谢
I would like to loop through months any days
- 为此,您可以将两个参数从您的管道传递给 activity,以便可以根据这些参数动态构建路径。 ADF V2 允许您传递参数。
让我们开始一个一个的过程:
1。创建一个管道并在其中为您的月份和日期传递两个参数。
注意:如果需要,也可以从其他活动的输出中传递此参数。参考:Parameters in ADF
2。创建两个数据集。
2.1 接收器数据集 - 此处为 Blob 存储。 Link 它与您的 Linked 服务并提供容器名称(确保它存在)。同样,如果需要,它可以作为参数传递。
2.2 源数据集 - Blob 存储再次出现或根据您的需要而定。 Link 它与您的 Linked 服务并提供容器名称(确保它存在)。同样,如果需要,它可以作为参数传递。
注:
1、文件夹路径决定复制数据的路径。如果容器不存在,activity 将为您创建,如果文件已经存在,默认情况下将覆盖该文件。
2. 如果要动态构建输出路径,则传递数据集中的参数。在这里,我为名为 monthcopy 和 datacopy 的数据集创建了两个参数。
3。在管道中创建副本 Activity。
通配符文件夹路径:
@{concat(formatDateTime(adddays(utcnow(),-1),'yyyy'),'/',string(pipeline().parameters.month),'/',string(pipeline().parameters.day),'/*')}
where:
The path will become as: current-yyyy/month-passed/day-passed/* (the * will take any folder on one level)
测试结果:
JSON 管道模板:
{
"name": "pipeline2",
"properties": {
"activities": [
{
"name": "Copy Data1",
"type": "Copy",
"dependsOn": [],
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false,
"secureInput": false
},
"userProperties": [],
"typeProperties": {
"source": {
"type": "DelimitedTextSource",
"storeSettings": {
"type": "AzureBlobStorageReadSettings",
"recursive": true,
"wildcardFolderPath": {
"value": "@{concat(formatDateTime(adddays(utcnow(),-1),'yyyy'),'/',string(pipeline().parameters.month),'/',string(pipeline().parameters.day),'/*')}",
"type": "Expression"
},
"wildcardFileName": "*.csv",
"enablePartitionDiscovery": false
},
"formatSettings": {
"type": "DelimitedTextReadSettings"
}
},
"sink": {
"type": "DelimitedTextSink",
"storeSettings": {
"type": "AzureBlobStorageWriteSettings"
},
"formatSettings": {
"type": "DelimitedTextWriteSettings",
"quoteAllText": true,
"fileExtension": ".csv"
}
},
"enableStaging": false
},
"inputs": [
{
"referenceName": "DelimitedText1",
"type": "DatasetReference"
}
],
"outputs": [
{
"referenceName": "DelimitedText2",
"type": "DatasetReference",
"parameters": {
"monthcopy": {
"value": "@pipeline().parameters.month",
"type": "Expression"
},
"datacopy": {
"value": "@pipeline().parameters.day",
"type": "Expression"
}
}
}
]
}
],
"parameters": {
"month": {
"type": "string"
},
"day": {
"type": "string"
}
},
"annotations": []
}
}
JSON SINK 数据集模板:
{
"name": "DelimitedText1",
"properties": {
"linkedServiceName": {
"referenceName": "AzureBlobStorage1",
"type": "LinkedServiceReference"
},
"annotations": [],
"type": "DelimitedText",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"container": "corpdata"
},
"columnDelimiter": ",",
"escapeChar": "\",
"quoteChar": "\""
},
"schema": []
}
}
JSON 源数据集模板:
{
"name": "DelimitedText2",
"properties": {
"linkedServiceName": {
"referenceName": "AzureBlobStorage1",
"type": "LinkedServiceReference"
},
"parameters": {
"monthcopy": {
"type": "string"
},
"datacopy": {
"type": "string"
}
},
"annotations": [],
"type": "DelimitedText",
"typeProperties": {
"location": {
"type": "AzureBlobStorageLocation",
"folderPath": {
"value": "@concat(formatDateTime(adddays(utcnow(),-1),'yyyy'),dataset().monthcopy,'/',dataset().datacopy)",
"type": "Expression"
},
"container": "copycorpdata"
},
"columnDelimiter": ",",
"escapeChar": "\",
"quoteChar": "\""
},
"schema": []
}
}