[英]Azure data factory data flow json to SQL
I have a source JSON file with hierarchical data, which I need to sink in two SQL tables(relational).我有一个包含分层数据的源 JSON 文件,我需要将其放入两个 SQL 表(关系)中。 The JSON is as below JSON 如下
{
"orders":[
{
"orderid":"30933",
"ordername":"abc",
"items":[
{
"itemid":1,
"itemstatus":"Failed"
},
{
"itemid":2,
"itemstatus":"Failed"
}
]
},
{
"orderid":"308320",
"ordername":"xyz",
"items":[
{
"itemid":5,
"itemstatus":"Succeeded"
}
]
}
]
}
My SQL holding two tables Order and OrderItem with OrderID primary and foreign key.我的 SQL 持有两个表 Order 和 OrderItem 与 OrderID 主键和外键。
Now I have an Azure data factory data flow with source as above JSON and I need to park all data relational in respective tables.现在我有一个 Azure 数据工厂数据流,其来源如上 JSON,我需要将所有数据关系停放在各个表中。
So here I need OrderId(30933,308320) and OrderName(abc,xyz) will go into Order table and respective items data go into OrderItem table(which reference OrderId from Order table).所以在这里我需要 OrderId(30933,308320) 和 OrderName(abc,xyz) 将 go 到 Order 表中,并将相应的项目数据 go 到 OrderItem 表中(从 Order 表中引用 OrderId)。 In this case Order table have 2 and OrderItem table have 3 entries.在这种情况下,Order 表有 2 个,OrderItem 表有 3 个条目。
We can not achieve that in one copy active.我们无法在一个副本中实现这一点。
We could using two copy actives in one pipeline, I tested and it succeed.我们可以在一个管道中使用两个副本活动,我测试过并且成功了。 You could follow my steps bellow:你可以按照我下面的步骤:
Orders
(orderid and ordername) to table Orders
.复制 active1:将数据从Orders
(orderid 和 ordername)复制到表Orders
中。items
(itemid and itemstatus) to table OrderItems
.复制 active2:将items
(itemid 和 itemstatus)中的数据复制到表OrderItems
中。Note:笔记:
Copy active 1 and 2 use the same json file as the source.复制活动 1 和 2 使用相同的 json 文件作为源文件。 The differences are in the Mapping settings.不同之处在于映射设置。
Copy active 1 sink is Azure SQL database table Orders
, Copy active 2 sink is Azure SQL database table OrderItems
. Copy active 1 sink is Azure SQL database table Orders
, Copy active 2 sink is Azure SQL database table OrderItems
.
To make you understand it clearly, I made two GIF pictures.为了让大家看清楚,我做了两张GIF图。
Mapping settings in Copy active 1: Copy active 1 中的映射设置:
Mapping settings in Copy active 2: Copy active 2 中的映射设置:
Run the pipeline:运行管道:
Check the data in table:检查表中的数据:
The limit is that we only could get the first element of items
, we can not choose the collection reference both.限制是我们只能获取items
的第一个元素,我们不能同时选择集合引用。
Update:更新:
Congratulations that you achieved it in another way: flatten/transpose the data using data flow and then maintain it to pour in a relational SQL table.恭喜您以另一种方式实现了它:使用数据流展平/转置数据,然后将其维护到关系 SQL 表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.