ADF - 迭代选择输出到复制活动

发布于 2025-01-20 01:55:29 字数 402 浏览 1 评论 0原文

我们有一个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

屏幕截图中的以下输出应使用ADF移动到多个表。我们如何实现这一目标?

注意:SP无法更改,这是一个示例脚本。

we have an SP where the SP executes and returns multiple result set with change in column number as below:

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. how to we achieve this?

enter image description here

Note: The SP cannot be changed and this is an example script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风无影 2025-01-27 01:55:29

如果该过程完全如您所描述的,那么新的脚本活动支持多个结果集,可以与对于每个活动或多个脚本活动,以并行浏览它们并将其加载到数据库表中。请记住脚本活动(就像查找活动)仅限于5,000行和2MB数据,因此它并不是要用于大规模数据导入,并且了解它与复制活动的根本不同,因为它将数据拉入管道中,你必须操纵。

一个简单的示例:

“在此处输入图像描述”

第一个脚本活动只是调用返回多个结果集的存储的proc。活动的输出看起来大致是这样的:

{
    "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": {},
...

如您所见,您的多个结果集现在正在管道中,可以操纵。结果集为0基于0,因此第一个(仅返回NUM1)为Resulteets [0],可以参考使用以下语法:

activity('Script0').output.resultSets[0]

因此,对于每个脚本活动,我们都有略有不同的语句:

script0-调用存储的proc:

EXEC usp_multipleResultSets;

script1-加载结果集0:

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

script2-加载结果集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-加载结果集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();' )

脚本类型应设置为script 0的查询 script 0,但可以是> >非Query其他人。

nb脚本任务确实允许您使用Plus(+)按钮添加多个脚本,但是它们会以序列形式运行。我在这里使用三个,因为我希望SQL的三个项目并行运行。

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

A simple example:

enter image description here

The first Script activity simply calls the stored proc that returns the multiple resultsets. The output from the activity looks roughly like this:

{
    "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:

activity('Script0').output.resultSets[0]

So for each Script activity we have slightly differing statements:

Script0 - call the stored proc:

EXEC usp_multipleResultSets;

Script1 - load resultset 0:

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

Script2 - load resultset 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:

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

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.

诗笺 2025-01-27 01:55:29

ADF现在具有SQL脚本活动,该活动允许多个结果集。

ADF now has the SQL Script activity which allows for multiple resultsets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文