繁体   English   中英

带有 Rest API 的 Azure 数据工厂 V2 复制活动为嵌套的 JSON 提供一行

[英]Azure Data Factory V2 Copy Activity with Rest API giving one row for nested JSON

我正在尝试展平从 Rest 源返回的嵌套 JSON。 流水线代码如下。 这里的问题是这个管道只从 JSON 数据集中返回第一个对象并跳过所有其余的行。 你能指导我如何迭代嵌套对象吗?

谢谢萨米特

{
    "name": "STG_NCR2",
    "properties": {
        "activities": [
            {
                "name": "Copy data1",
                "type": "Copy",
                "dependsOn": [],
                "policy": {
                    "timeout": "7.00:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                },
                "userProperties": [],
                "typeProperties": {
                    "source": {
                        "type": "RestSource",
                        "httpRequestTimeout": "00:01:40",
                        "requestInterval": "00.00:00:00.010",
                        "requestMethod": "GET",
                        "additionalHeaders": {
                            "OData-MaxVersion": "4.0",
                            "OData-Version": "4.0",
                            "Prefer": "odata.include-annotations=*"
                        }
                    },
                    "sink": {
                        "type": "AzureSqlSink"
                    },
                    "enableStaging": false,
                    "translator": {
                        "type": "TabularTranslator",
                        "mappings": [
                            {
                                "source": {
                                    "path": "$['value'][0]['tco_ncrid']"
                                },
                                "sink": {
                                    "name": "NCRID"
                                }
                            },
                            {
                                "source": {
                                    "path": "['tco_name']"
                                },
                                "sink": {
                                    "name": "EquipmentSerialNumber"
                                }
                            }
                        ],
                        "collectionReference": "$['value'][0]['tco_ncr_tco_equipment']"
                    }
                },
                "inputs": [
                    {
                        "referenceName": "Rest_PowerApps_NCR",
                        "type": "DatasetReference"
                    }
                ],
                "outputs": [
                    {
                        "referenceName": "Prestaging_PowerApps_NCREquipments",
                        "type": "DatasetReference"
                    }
                ]
            }
        ],
        "annotations": []
    }
}

JSON 格式如下

[ 
   { 
      "value":[ 
         { 
            "tco_ncrid":"abc-123",
            "tco_ncr_tco_equipment":[ 
               { 
                  "tco_name":"abc"
               }
            ]
         },
         { 
            "tco_ncrid":"abc-456",
            "tco_ncr_tco_equipment":[ 
               { 
                  "tco_name":"xyz"
               },
               { 
                  "tco_name":"yzx"
               }
            }
         ]
      ]
   }
]

这可以通过如下修改翻译器属性来解决。

"translator": {
                    "type": "TabularTranslator",
                    "mappings": [
                        {
                            "source": {
                                "path": "$.['value'][0].['tco_ncrid']"
                            },
                            "sink": {
                                "name": "NCRID",
                                "type": "String"
                            }
                        },
                        {
                            "source": {
                                "path": "$.['value'][0].['tco_text_id']"
                            },
                            "sink": {
                                "name": "EquipmentDescription",
                                "type": "String"
                            }
                        },
                        {
                            "source": {
                                "path": "['tco_name']"
                            },
                            "sink": {
                                "name": "EquipmentSerialNumber",
                                "type": "String"
                            }
                        }
                    ],
                    "collectionReference": "$.['value'][*].['tco_ncr_tco_equipment']"
                }

此代码强制管道迭代嵌套数组,但您可以看到 NCRID 被硬编码为值数组的第一个元素。 这不是我想要的,因为我正在寻找针对每个 NCRID 的所有设备序列号。 还在研究中...

暂无
暂无

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

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