简体   繁体   English

如何使用 ADF 将列转换为数组

[英]How to transform a column into an array using ADF

I need to read a column on a db on ADF and use all it´s values as parameters in a foreach.我需要读取 ADF 上数据库中的一列,并将其所有值用作 foreach 中的参数。

I tried reading the column using a dataflow and a cache sink to then in a pipeline use Set Variable and then the foreach...but instead of an array of values I get an array with one value that contains all the others I want (but i cant iterate over) I am using: @array(activity('myDataflow').output.runStatus.output.columName我尝试使用数据流和缓存接收器读取列,然后在管道中使用 Set Variable 然后使用 foreach ...但是我得到的不是值数组,而是一个包含一个值的数组,其中包含我想要的所有其他值(但是我无法迭代)我正在使用: @array(activity('myDataflow').output.runStatus.output.columName

Any help is appreciated, seems simple enough (column to array) but I am stuck感谢任何帮助,看起来很简单(从列到数组)但我被卡住了

Use a lookup activity to get the data from SQL server, and run for each loop on the output of the lookup.使用查找活动从 SQL 服务器获取数据,并在查找的 output 上运行每个循环。 Example:例子:

  1. Create a new pipeline创建新管道

  2. Add a lookup activity添加查找活动

  3. Choose your source dataset (in this example, an Azure SQL database)选择您的源数据集(在本例中为 Azure SQL 数据库)

  4. Remove the checkbox from “First row only”取消勾选“仅第一行”

  5. Choose a table, stored procedure or type in a query选择表、存储过程或输入查询

    SELECT 1 AS result UNION ALL SELECT 2 AS result UNION ALL SELECT 3 AS result UNION ALL SELECT 4 AS result SELECT 1 作为结果 UNION ALL SELECT 2 作为结果 UNION ALL SELECT 3 作为结果 UNION ALL SELECT 4 作为结果查找活动

  6. Add a foreach activity添加一个 foreach 活动

  7. In the foreach activity, under settings tab: “Items” - @activity('Lookup SQL query').output.value – where 'Lookup SQL query' is the name of the lookup activity在 foreach 活动中,在设置选项卡下:“Items” - @activity('Lookup SQL query').output.value – 其中 'Lookup SQL query' 是查找活动的名称每项活动

  8. Inside the foreach loop, add a wait activity在 foreach 循环中,添加一个等待活动

  9. In the settings tab, “Wait time in seconds”: @item().result.在设置选项卡中,“以秒为单位的等待时间”:@item().result。 item() is the current loop, and result is the name of the SQL column item()是当前循环,result是SQL列的名字等待活动

debug the pipeline.调试管道。 You can see that the foreach activity iterates 4 times, for every row returned from the sql query.您可以看到 foreach 活动针对从 sql 查询返回的每一行迭代了 4 次。 查找活动结果

You can use append variable activity also, inside ForEach after lookup.您也可以在查找后在ForEach内部使用 append 变量活动。

First create an array variable in the pipeline.首先在管道中创建一个数组变量。

在此处输入图像描述

Then use append variable activity inside ForEach and give然后在 ForEach 中使用 append 变量活动并给出

@item.<your_column_name>

在此处输入图像描述

Result variable stored in a sample variable:存储在示例变量中的结果变量:

在此处输入图像描述

Result:结果:

在此处输入图像描述

I tried reading the column using a dataflow and a cache sink to then in a pipeline use Set Variable and then the foreach我尝试使用数据流和缓存接收器读取列,然后在管道中使用 Set Variable 然后使用 foreach

If you want to do it with dataflows instead of lookup, use the same above procedure and give the below dynamic content in the ForEach.如果您想使用数据流而不是查找来执行此操作,请使用与上述相同的过程并在 ForEach 中提供以下动态内容。

@activity('Data flow1').output.runStatus.output.sink1.value

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM