使用 utcnow() 作为管道参数的 Azure 数据工厂 v2

Tho*_*get 5 azure azure-data-factory azure-data-factory-2

对于上下文,我目前有一个 Data Factory v2 管道,其中有一个ForEach Activity调用Copy Activity。该复制活动只是从FTP服务器到Blob存储容器复制数据。

这是管道 json 文件:

{
    "name": "pipeline1",
    "properties": {
        "activities": [
            {
                "name": "ForEach1",
                "type": "ForEach",
                "typeProperties": {
                    "items": {
                        "value": "@pipeline().parameters.InputParams",
                        "type": "Expression"
                    },
                    "isSequential": true,
                    "activities": [
                        {
                            "name": "Copy1",
                            "type": "Copy",
                            "policy": {
                                "timeout": "7.00:00:00",
                                "retry": 0,
                                "retryIntervalInSeconds": 30,
                                "secureOutput": false
                            },
                            "typeProperties": {
                                "source": {
                                    "type": "FileSystemSource",
                                    "recursive": true
                                },
                                "sink": {
                                    "type": "BlobSink"
                                },
                                "enableStaging": false,
                                "cloudDataMovementUnits": 0
                            },
                            "inputs": [
                                {
                                    "referenceName": "FtpDataset",
                                    "type": "DatasetReference",
                                    "parameters": {
                                        "FtpFileName": "@item().FtpFileName",
                                        "FtpFolderPath": "@item().FtpFolderPath"
                                    }
                                }
                            ],
                            "outputs": [
                                {
                                    "referenceName": "BlobDataset",
                                    "type": "DatasetReference",
                                    "parameters": {
                                        "BlobFileName": "@item().BlobFileName",
                                        "BlobFolderPath": "@item().BlobFolderPath"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "parameters": {
            "InputParams": {
                "type": "Array",
                "defaultValue": [
                    {
                        "FtpFolderPath": "/Folder1/",
                        "FtpFileName": "@concat('File_',formatDateTime(utcnow(), 'yyyyMMdd'), '.txt')",
                        "BlobFolderPath": "blobfolderpath",
                        "BlobFileName": "blobfile1"
                    },
                    {
                        "FtpFolderPath": "/Folder2/",
                        "FtpFileName": "@concat('File_',formatDateTime(utcnow(), 'yyyyMMdd'), '.txt')",
                        "BlobFolderPath": "blobfolderpath",
                        "BlobFileName": "blobfile2"
                    }
                ]
            }
        }
    },
    "type": "Microsoft.DataFactory/factories/pipelines"
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,在指定管道参数时,我似乎无法像在为 blob 存储数据集指定文件夹路径时那样使用系统变量和函数。这样做的结果是它formatDateTime(utcnow(), 'yyyyMMdd')不会被解释为函数调用,而是被解释为具有 value 的实际字符串formatDateTime(utcnow(), 'yyyyMMdd')

为了解决这个问题,我猜我应该使用触发器来执行我的管道并将触发器的执行时间作为参数传递给管道,trigger().startTime但这是唯一的方法吗?我只是在管道的 JSON 中做错了什么吗?

小智 8

这应该有效: File_@{formatDateTime(utcnow(), 'yyyyMMdd')}

或者复杂的路径:

rootfolder/subfolder/@{formatDateTime(utcnow(),'yyyy')}/@{formatDateTime(utcnow(),'MM')}/@{formatDateTime(utcnow(),'dd')}/@{formatDateTime(utcnow(),'HH')}
Run Code Online (Sandbox Code Playgroud)


Dra*_*anB 2

您不能将动态表达式放入默认值中。您应该在创建触发器时或在复制活动的接收器/源中定义数据集参数时定义此表达式和函数。因此,您可以在源数据集中使用某些默认值创建数据集属性 FtpFileName,然后在复制活动中,您可以在源类别中指定该动态表达式。

例子

另一种方法是定义管道参数,然后在定义触发器时向该管道参数添加动态表达式。希望这对您来说是一个明确的答案。:)