[英]ADF - Iterative select Output to Copy activity
we have an SP where the SP executes and returns multiple result set with change in column number as below:我们有一个 SP,其中 SP 执行并返回多个结果集,列号发生变化,如下所示:
create proc test ab
as
select 1 as num1
select 1 as num1, 2 as num2
select 1 as num1, 2 as num2,3 as num3
The below output in screenshot should be moved to multiple tables using ADF.应使用 ADF 将以下屏幕截图中的 output 移动到多个表。 how to we achieve this?我们如何做到这一点?
Note: The SP cannot be changed and this is an example script.注意:无法更改 SP,这是一个示例脚本。
If the process is exactly as you describe, then the new Script activity supports multiple resultsets and can be combined with a For Each activity or multiple Script activities to walk through them in parallel and load them to database tables.如果流程与您描述的完全一致,那么新的脚本活动支持多个结果集,并且可以与For Each 活动或多个脚本活动结合使用,以并行遍历它们并将它们加载到数据库表中。 Please bear in mind that the Script activity (just like the Lookup activity ) is limited to 5,000 rows and 2MB of data, so it's not meant for large-scale data imports, and understand that it is fundamentally different to the Copy activity in that it pulls data into the pipeline which you have to manipulate.请记住,Script 活动(就像Lookup 活动一样)限制为 5,000 行和 2MB 的数据,因此它不适用于大规模数据导入,并了解它与 Copy 活动的根本区别在于它将数据拉入您必须操作的管道中。
A simple example:一个简单的例子:
The first Script activity simply calls the stored proc that returns the multiple resultsets.第一个脚本活动只是调用返回多个结果集的存储过程。 The output from the activity looks roughly like this:活动中的 output 大致如下所示:
{
"resultSetCount": 3,
"recordsAffected": 0,
"resultSets": [
{
"rowCount": 1,
"rows": [
{
"num1": 1
}
]
},
{
"rowCount": 1,
"rows": [
{
"num1": 1,
"num2": 2
}
]
},
{
"rowCount": 1,
"rows": [
{
"num1": 1,
"num2": 2,
"num3": 3
}
]
}
],
"outputParameters": {},
...
As you can see, your multiple resultsets are now in the pipeline and can be manipulated.如您所见,您的多个结果集现在已在管道中并且可以进行操作。 The resultsets are 0-based, so the first one (which returns only num1) is resultSets[0]
and they can be referred to using the following syntax:结果集是从 0 开始的,因此第一个(仅返回 num1)是resultSets[0]
并且可以使用以下语法引用它们:
activity('Script0').output.resultSets[0]
So for each Script activity we have slightly differing statements:因此,对于每个脚本活动,我们的陈述略有不同:
EXEC usp_multipleResultSets;
@concat('INSERT INTO dbo.multipleResultSets ( num1, dateAdded ) SELECT ', activity('Script0').output.resultSets[0].rows[0].num1, ', GETDATE();' )
@concat('INSERT INTO dbo.multipleResultSets ( num1, num2, dateAdded ) SELECT ', activity('Script0').output.resultSets[1].rows[0].num1, ', ', activity('Script0').output.resultSets[1].rows[0].num2, ', GETDATE();' )
@concat('INSERT INTO dbo.multipleResultSets ( num1, num2, num3, dateAdded ) SELECT ', activity('Script0').output.resultSets[2].rows[0].num1, ', ', activity('Script0').output.resultSets[2].rows[0].num2, ', ', activity('Script0').output.resultSets[2].rows[0].num3, ', GETDATE();' )
The Script type should be set to Query
for Script 0 but can be NonQuery
for the others.对于脚本 0,脚本类型应设置为Query
,但对于其他脚本类型可以设置NonQuery
查询。
NB The Script task does allow you to add multiple scripts using the plus (+) button but they would then run in serial.注意:脚本任务确实允许您使用加号 (+) 按钮添加多个脚本,但它们随后会连续运行。 I'm using three here as I want the three items of SQL to run in parallel.我在这里使用三个,因为我希望 SQL 的三个项目并行运行。
ADF now has the SQL Script activity which allows for multiple resultsets. ADF 现在具有允许多个结果集的 SQL 脚本活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.