首页 文章

Azure Data Factory v2使用utcnow()作为管道参数

提问于
浏览
0

对于上下文,我目前有一个Data Factory v2管道,其中包含一个调用Copy活动的ForEach 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" }

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

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

2 回答

  • 0

    您不能将动态表达式放在默认值中 . 您应该在创建触发器时或在复制活动中的sink / source中定义数据集参数时定义此表达式和函数 . 因此,要么在源数据集中创建具有某个默认值的数据集属性FtpFileName,然后在复制活动中,您可以在源类别中指定该动态表达式 .

    example

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

  • 0

    参数的默认值不能是表达式 . 它们必须是文字字符串 . 您可以使用触发器来实现此目的 . 或者,您可以提取表达式的公共部分,并将文字值放入foreach项中 .

相关问题