Azure Datafactory v2分别执行管道

时间:2020-04-08 21:03:07

标签: azure azure-data-factory azure-data-factory-2

我正在尝试使用“执行管道”来调用具有ForEach活动的管道。我收到错误消息。

  1. 用于执行管道的Json:
[
    {
        "name": "pipeline3",
        "properties": {
            "activities": [
                {
                    "name": "Test_invoke1",
                    "type": "ExecutePipeline",
                    "dependsOn": [],
                    "userProperties": [],
                    "typeProperties": {
                        "pipeline": {
                            "referenceName": "MAIN_SA_copy1",
                            "type": "PipelineReference"
                        },
                        "waitOnCompletion": true
                    }
                }
            ],
            "annotations": []
        }
    }
]
  1. Jason为每个活动调用管道:
[
    {
        "name": "MAIN_SA_copy1",
        "properties": {
            "activities": [
                {
                    "name": "Collect_SA_Data",
                    "type": "ForEach",
                    "dependsOn": [],
                    "userProperties": [],
                    "typeProperties": {
                        "items": {
                            "value": "@pipeline().parameters.TableNames",
                            "type": "Expression"
                        },
                        "batchCount": 15,
                        "activities": [
                            {
                                "name": "Sink_SAdata_toDL",
                                "type": "Copy",
                                "dependsOn": [],
                                "policy": {
                                    "timeout": "7.00:00:00",
                                    "retry": 0,
                                    "retryIntervalInSeconds": 30,
                                    "secureOutput": false,
                                    "secureInput": false
                                },
                                "userProperties": [
                                    {
                                        "name": "Destination",
                                        "value": "@{pipeline().parameters.DLFilePath}/@{item()}"
                                    }
                                ],
                                "typeProperties": {
                                    "source": {
                                        "type": "SqlServerSource",
                                        "sqlReaderQuery": {
                                            "value": "@concat('SELECT * FROM ',item())",
                                            "type": "Expression"
                                        }
                                    },
                                    "sink": {
                                        "type": "AzureBlobFSSink"
                                    },
                                    "enableStaging": false,
                                    "parallelCopies": 1,
                                    "dataIntegrationUnits": 4
                                },
                                "inputs": [
                                    {
                                        "referenceName": "SrcDS_StructuringAnalytics",
                                        "type": "DatasetReference"
                                    }
                                ],
                                "outputs": [
                                    {
                                        "referenceName": "ADLS",
                                        "type": "DatasetReference",
                                        "parameters": {
                                            "FilePath": "@pipeline().parameters.DLFilePath",
                                            "FileName": {
                                                "value": "@concat(item(),'.orc')",
                                                "type": "Expression"
                                            }
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            ],
            "parameters": {
                "DLFilePath": {
                    "type": "string",
                    "defaultValue": "extracts/StructuringAnalytics"
                },
                "TableNames": {
                    "type": "array",
                    "defaultValue": [
                        "fom.FOMLineItem_manual"
                    ]
                }
            },
            "variables": {
                "QryTableColumn": {
                    "type": "String"
                },
                "QryTable": {
                    "type": "String"
                }
            },
            "folder": {
                "name": "StructuringAnalytics"
            },
            "annotations": []
        },
        "type": "Microsoft.DataFactory/factories/pipelines"
    }
]

我收到一个错误:

[
    {
        "errorCode": "BadRequest",
        "message": "Operation on target Collect_SA_Data failed: The execution of template action 'Collect_SA_Data' failed: the result of the evaluation of 'foreach' expression '@pipeline().parameters.TableNames' is of type 'String'. The result must be a valid array.",
        "failureType": "UserError",
        "target": "Test_invoke1",
        "details": ""
    }
]

输入:

"pipeline": {
    "referenceName": "MAIN_SA_copy1",
    "type": "PipelineReference"
},
"waitOnCompletion": true,
"parameters": {
    "DLFilePath": "extracts/StructuringAnalytics",
    "TableNames": "[\"fom.FOMLineItem_manual\"]"
}

2 个答案:

答案 0 :(得分:0)

请尝试如下更新ForEach项目的动态表达式:

{
    "value": "@array(pipeline().parameters.TableNames)",
    "type": "Expression"
}

enter image description here

希望这会有所帮助。

答案 1 :(得分:0)

我猜您正在使用 UI 来设置管道及其参数,我猜您希望将被调用管道的数组参数放在其他地方,如下所示: (这都是我的猜测,因为我只是做了完全一样的,得到了​​同样的结果)

Wrong

诀窍是在代码中定义数组(["table1", "table2"]): Code

UI 中的输入将如下所示:

Right

现在可以了!
看来,Datafactory 将整个数组视为某个数组的一个元素。因此,使用 array() 函数的解决方案有时有效。
看起来是个bug,定义数组参数输入..

(不得不编辑答案,我最初认为在 UI 输入中省略冒号就足够了)