azure - 使用 Azure 数据工厂中的 REST API 映射嵌套 JSON,通过存储过程将每个迭代器使用到 SQL 表

标签 azure stored-procedures azure-data-factory

我正在 ADF 中使用 REST API 提取管道列表。 API 提供了一个嵌套的 JSON,我正在使用一个 for 每个迭代器,通过存储过程将其拉入 SQL 表中。

示例 JSON 如下所示:

 {
  "value": [
    {
    "id": "ADF/pipelines/v_my_data_ww",
    "name": "v_my_data_ww",
    "type": "MS.DF/factories/pipelines",
    "properties": {
    "activities": [
      {
        "name": "Loaddata_v_my_data_ww",
        "type": "Copy",
        "dependsOn": [],
        "policy": {
          "timeout": "7.00:00:00",
          "retry": 0,
          "retryIntervalInSeconds": 30,
          "secureOutput": false,
          "secureInput": false
      }
     ]
     },
     "folder": {
      "name": "myData"
      },
      "annotations": [],
      "lastPublishTime": "2021-04-01T22:09:20Z"
     ,
     "etag": "iaui7881919"
         }
   }
  ]
}

因此,使用 For Each Iterator @activity('Web1').output.value,我能够提取主键,例如 id、name 、类型。但是,我还需要从属性/事件标记中提取名称/类型。不知道该怎么做。我正在尝试以下操作。

enter image description here

enter image description here

当我运行管道时,出现以下错误:

The expression 'item().properties.activities.name' cannot be evaluated because property 'name' cannot be selected. Array elements can only be selected using an integer index.

我们将非常感谢这方面的任何帮助。

最佳答案

该错误是因为您尝试直接使用 key 访问数组,即activities。我们需要使用索引访问数组元素,例如 activities[0]

  • 以下演示了如何解决此问题。当我使用 @item().properties.activities.name 时,我遇到了同样的错误。

enter image description here

  • 为了演示如何解决此问题,我将给定的示例 json 作为管道参数,并为每个事件传递 @pipeline().parameters.js.value

enter image description here

  • 现在,我使用了一个设置变量来展示如何检索 activities 属性中存在的名称和类型。以下动态内容有助于实现这一目标。
@item().properties.activities[0].name

enter image description here

因此,将您的 prop_nameprop_type 修改为以下动态内容:

@item().properties.activities[0].name
@item().properties.activities[0].type

更新:

如果activities属性数组中有多个对象,则可以按照以下步骤操作:

  • 创建一个执行管道事件来执行名为loop_activities的管道。在loop_activities管道name、id、tp、activities中创建4个参数。传递动态内容如下图:

enter image description here

  • loop_activities管道中,使用foreach来迭代activities数组。 items 字段的动态内容值为 @pipeline().parameters.activities

  • 在每个元素内部,您可以使用以下动态内容访问每个必需的元素。

#for name:
@pipeline().parameters.name

#for id:
@pipeline().parameters.id

#for type:
@pipeline().parameters.type

#for prop_name:
@item().name

#for prop_type:
@item().type

  • 以下是我运行 pipeline1loop_activities 的调试输出(仅适用于 prop_name 和 prop_type)。

enter image description here

关于azure - 使用 Azure 数据工厂中的 REST API 映射嵌套 JSON,通过存储过程将每个迭代器使用到 SQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73629918/

相关文章:

macos - Azure cli 提示未在命名空间中注册

azure - 未从 azure 服务总线订阅获取所有代理消息

postgresql - Postgresql 中的存储过程中的表别名不存在架构

azure - 自托管集成运行时是否有轮询间隔设置?

azure - 删除无法使用 CI CD 管道工作的数据工厂组件

powershell - 上传到Azure后删除本地文件

c# - Azure DocumentDB 偶尔抛出 SocketException/GoneException

mysql - 无法使用 MySQL 创建存储过程

java - 从 Java 调用 Oracle 类型 TABLE 的存储过程

dataset - 如何在 ADFv2 中以表达式作为值传递参数?