ADF中如何在Foreach内通过Execute Pipeline传递列名与脚本输出至子管道
Azure Data Factory 两个需求的解决方案
首先明确你提供的脚本活动输出结构:
{ "resultSetCount": 1, "recordsAffected": 21, "resultSets": [ { "rowCount": 21, "rows": [ { "name": "EMPID", "type": "NUMBER(12,0)", "kind": "COLUMN", "null?": "Y", "default": null, "primary key": "N", "unique key": "N", "check": null, "expression": null, "comment": "T", "policy name": null, "privacy domain": null }, { "name": "NAME", "type": "VARCHAR(16777216)", "kind": "COLUMN", "null?": "Y", "default": null, "primary key": "N", "unique key": "N", "check": null, "expression": null, "comment": "The name of the tablespace this record comes from", "policy name": null, "privacy domain": null } ] } ] }
需求1:Foreach活动内通过Execute Pipeline传递父管道列名给子管道
按以下步骤配置:
- 子管道侧:在子管道的「参数」页面新建参数,命名为
TargetColumnName,类型选择「字符串」。 - 父管道侧:
- 配置Foreach活动的「迭代项」为脚本输出的行数据,表达式写:
@activity('你的脚本活动名称').output.resultSets[0].rows - 在Foreach内部添加Execute Pipeline活动,选择你要调用的子管道。
- 切换到Execute Pipeline的「参数」标签,找到子管道的
TargetColumnName参数,赋值为@item().name(这里的name对应脚本输出中存储列名的字段)。
- 配置Foreach活动的「迭代项」为脚本输出的行数据,表达式写:
- 子管道内使用:在子管道的任意活动中,用
@pipeline().parameters.TargetColumnName就能获取传递过来的列名。
需求2:将脚本活动的输出传递给Execute Pipeline供子管道使用
分两种场景处理:
场景1:传递脚本活动的完整输出
- 子管道侧:新建参数
ScriptFullOutput,类型选择「对象」。 - 父管道侧:在Execute Pipeline的参数配置中,给
ScriptFullOutput赋值为@activity('你的脚本活动名称').output。 - 子管道内引用示例:
- 获取结果集数量:
@pipeline().parameters.ScriptFullOutput.resultSetCount - 获取第一行的列名:
@pipeline().parameters.ScriptFullOutput.resultSets[0].rows[0].name
- 获取结果集数量:
场景2:仅传递脚本输出的列数据集(rows数组)
- 子管道侧:新建参数
ColumnRows,类型选择「数组」。 - 父管道侧:赋值为
@activity('你的脚本活动名称').output.resultSets[0].rows。 - 子管道内使用:比如在子管道的Foreach活动中,设置迭代项为
@pipeline().parameters.ColumnRows,然后用@item().name获取列名,@item().type获取列数据类型。
内容的提问来源于stack exchange,提问作者Vamshi Reddy
相关产品推荐
相关产品推荐

