如何使用 Azure 数据工厂 v2 (adf) 在文件夹中查找最新文件
How to find the latest file in folder using azure data factory v2 (adf)
我正在尝试使用 Azure 数据工厂 v2 读取最新的 blob 文件 (csv)。文件名还包含日期(YYYY-MM-DD mm:ss-abcd.csv)。我需要从存在的最新文件中读取数据并加载到 table 存储中。你能帮我看看如何使用 ADF
读取最新文件吗
您好 Faiz Rahman,感谢您提出问题。您选择的日期格式具有字典排序匹配时间排序的有用功能。这意味着,一旦您有了 blob 列表,只需提取日期并进行比较即可。
如果您有非常大的 blob 列表,这可能不切实际。在这种情况下,每当您编写一个新的 blob 时,在某个地方跟踪它,比如 "maxBlobName.txt",并让管道读取它以获取最新文件的名称。
下面是一些示例代码,用于比较 blob 名称的日期部分。为了适应您的目的,您将需要使用 GetMetadata activity 来获取 blob 名称,并使用一些字符串函数来仅提取名称的日期部分以进行比较。
{
"name": "pipeline9",
"properties": {
"activities": [
{
"name": "ForEach1",
"type": "ForEach",
"dependsOn": [
{
"activity": "init array",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"items": {
"value": "@variables('list')",
"type": "Expression"
},
"isSequential": true,
"activities": [
{
"name": "If Condition1",
"type": "IfCondition",
"typeProperties": {
"expression": {
"value": "@greater(item(),variables('max'))",
"type": "Expression"
},
"ifTrueActivities": [
{
"name": "write new max",
"type": "SetVariable",
"typeProperties": {
"variableName": "max",
"value": {
"value": "@item()",
"type": "Expression"
}
}
}
]
}
}
]
}
},
{
"name": "init array",
"type": "SetVariable",
"typeProperties": {
"variableName": "list",
"value": {
"value": "@split(pipeline().parameters.input,',')",
"type": "Expression"
}
}
}
],
"parameters": {
"input": {
"type": "string",
"defaultValue": "'2019-07-25','2018-06-13','2019'-06-24','2019-08-08','2019-06-23'"
}
},
"variables": {
"max": {
"type": "String",
"defaultValue": "0001-01-01"
},
"list": {
"type": "Array"
}
}
}
}
我正在尝试使用 Azure 数据工厂 v2 读取最新的 blob 文件 (csv)。文件名还包含日期(YYYY-MM-DD mm:ss-abcd.csv)。我需要从存在的最新文件中读取数据并加载到 table 存储中。你能帮我看看如何使用 ADF
读取最新文件吗您好 Faiz Rahman,感谢您提出问题。您选择的日期格式具有字典排序匹配时间排序的有用功能。这意味着,一旦您有了 blob 列表,只需提取日期并进行比较即可。
如果您有非常大的 blob 列表,这可能不切实际。在这种情况下,每当您编写一个新的 blob 时,在某个地方跟踪它,比如 "maxBlobName.txt",并让管道读取它以获取最新文件的名称。
下面是一些示例代码,用于比较 blob 名称的日期部分。为了适应您的目的,您将需要使用 GetMetadata activity 来获取 blob 名称,并使用一些字符串函数来仅提取名称的日期部分以进行比较。
{
"name": "pipeline9",
"properties": {
"activities": [
{
"name": "ForEach1",
"type": "ForEach",
"dependsOn": [
{
"activity": "init array",
"dependencyConditions": [
"Succeeded"
]
}
],
"typeProperties": {
"items": {
"value": "@variables('list')",
"type": "Expression"
},
"isSequential": true,
"activities": [
{
"name": "If Condition1",
"type": "IfCondition",
"typeProperties": {
"expression": {
"value": "@greater(item(),variables('max'))",
"type": "Expression"
},
"ifTrueActivities": [
{
"name": "write new max",
"type": "SetVariable",
"typeProperties": {
"variableName": "max",
"value": {
"value": "@item()",
"type": "Expression"
}
}
}
]
}
}
]
}
},
{
"name": "init array",
"type": "SetVariable",
"typeProperties": {
"variableName": "list",
"value": {
"value": "@split(pipeline().parameters.input,',')",
"type": "Expression"
}
}
}
],
"parameters": {
"input": {
"type": "string",
"defaultValue": "'2019-07-25','2018-06-13','2019'-06-24','2019-08-08','2019-06-23'"
}
},
"variables": {
"max": {
"type": "String",
"defaultValue": "0001-01-01"
},
"list": {
"type": "Array"
}
}
}
}