简体   繁体   English

ADF - 迭代 select Output 到复制活动

[英]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:因此,对于每个脚本活动,我们的陈述略有不同:

Script0 - call the stored proc: Script0 - 调用存储过程:

EXEC usp_multipleResultSets;

Script1 - load resultset 0:脚本 1 - 加载结果集 0:

@concat('INSERT INTO dbo.multipleResultSets ( num1, dateAdded ) SELECT ', activity('Script0').output.resultSets[0].rows[0].num1, ', GETDATE();' )

Script2 - load resultset 1:脚本 2 - 加载结果集 1:

@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();' )

Script3 - load resultset 2:脚本 3 - 加载结果集 2:

@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.

相关问题 ADF - 访问脚本任务活动 output 中使用的 #table 或临时表,以作为源在复制活动中使用 - ADF - Access #table or Temp table used in Script task activity output to be used in Copy activity as source ADF - 如何在复制活动中禁用映射 - ADF - How to disable mapping in Copy Activity ADF 复制活动不复制所有数据 - ADF Copy Activity Not copying all data 如何使用 .net sdk 在 Adf 复制活动中使用查询? - How to use query in Adf copy activity by using .net sdk? 使用ADF Copy Activity,我需要将.zip中的.seq文件解压并转换为csv - Using ADF Copy Activity, I need to unzip and convert .seq files in .zip to csv 当 CSV 在 header 列中有空间时,ADF 复制活动失败 CSV 到 Parquet - ADF Copy Activity Fails CSV to Parquet when CSV has space in header column 如何在 json 中为 azure 数据工厂 (adf) 中的复制活动添加默认日期,同时在 SQL 源和接收器之间动态映射列 - How to Add default date in json for copy activity in azure data factory(adf) while dynamic mapping of columns between SQL source and sink ADF 活动成功不会继续进行下一个活动 - ADF activity succeeded does not move on to the next activity SQL 在 ADF 中使用脚本活动进行查询 - SQL Query using script activity in ADF 如何在 Azure 数据工厂的复制活动中捕获 output 值 - How to capture an output value in Copy Activity in Azure Data Factory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM