0

I have a source JSON file with hierarchical data, which I need to sink in two SQL tables(relational). The JSON is as below

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

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.

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). In this case Order table have 2 and OrderItem table have 3 entries.

4
  • which data to which table, please clarify it to us? Commented Aug 6, 2020 at 9:35
  • @LeonYue I've just updated the question. Commented Aug 6, 2020 at 10:11
  • Hi @Manish Jain, If my answer is helpful for you, hope you can accept it as answer. This can be beneficial to other community members. Thank you. If you have any other concerns, please let us know. Commented Aug 10, 2020 at 0:58
  • @LeonYue,Thanks for your time and effort. Sure I'll check it and do it. Commented Aug 12, 2020 at 8:37

1 Answer 1

1

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:

  1. Copy active1: copy the data from Orders(orderid and ordername) to table Orders.
  2. Copy active2: copy the data from items(itemid and itemstatus) to table OrderItems.

Note:

  1. Copy active 1 and 2 use the same json file as the source. The differences are in the Mapping settings.

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

Mapping settings in Copy active 1: enter image description here

Mapping settings in Copy active 2: enter image description here

Run the pipeline:

enter image description here

Check the data in table:

enter image description here

The limit is that we only could get the first element of items, we can not choose the collection reference both.

enter image description here

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Actually I achieved it in another way, but as per your knowledge, I would say the answer will productive to others. I flatten/transpose the data using data flow and then maintain it to pour in a relational SQL table.
@ManishJain Congratulations! I will update my answer. Thanks for share the workaround for us.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.