0

I am a newbie in Azure so I read the Microsoft Table​Operation.​Merge Method.

Creates a new table operation that merges the contents of the given entity with the existing entity in a table.

That is all... Now, what should I understand from the "merge" concept? How exactly this Merge happens.

Say I have

Body {PK: b, RK: 1, LeftHand: null, RightHand: 1000, LeftLeg: ll} >
Body {PK: b, RK: 1, LeftHand: 9999, RightHand: null, Head: h}
  • What happens with empty/null values?
  • What happens if the item is not found?
  • What kind of exceptions should I expect?
  • What is the difference between InsertOrMerge and Merge?

How can I guess ?

serge
  • 13,940
  • 35
  • 121
  • 205

1 Answers1

1

Merge operation actually creates a superset. To put it simply:

  • If old entity doesn't have an attribute and the new one does: The resulting entity will have that new attribute.
  • If old entity has an attribute and the new one does not: That attribute's value will not be changed. It will be the same as that of the old value.
  • If old entity has an attribute and the new one also has that attribute: The resulting entity will replace the attribute value.

So in your example:

Old Entity:

{PK: b, RK: 1, LeftHand: null, RightHand: 1000, LeftLeg: ll}

New Entity:

{PK: b, RK: 1, LeftHand: 9999, RightHand: null, Head: h}

Entity After Merge Operation:

{PK: b, RK: 1, LeftHand: 9999, RightHand: 1000, LeftLeg: 11, Head: h} 
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Ok, but what happens if there is no old entity? – serge Jul 25 '17 at 09:55
  • also how do I force *null* in the RightHand or delete the Head? via Replace, I guess? – serge Jul 25 '17 at 09:57
  • `how I force null in the RightHand` - You would need to use `Replace` and not merge. `What happens if there is no old entity` - What do you mean by that? – Gaurav Mantri Jul 25 '17 at 09:57
  • I mean that no entity PK:b RK:1 in the Table yet – serge Jul 25 '17 at 09:58
  • You would essentially use `Upsert` functionality - `InsertOrMerge` or `InsertOrReplace`. – Gaurav Mantri Jul 25 '17 at 09:59
  • I mean, the documentation does not explain what to expect in that case of a new entry... – serge Jul 25 '17 at 10:00
  • I'm not sure I understand. Can you elaborate more please? – Gaurav Mantri Jul 25 '17 at 10:01
  • I Merge a newly created `Body {pk:b, rk:999}` that does not exist in the Table, I mean, there is no `Body {pk:b, rk:999}` in the table yet. What will happen? should I expect an exception or just no action, or an insert? – serge Jul 25 '17 at 10:04
  • 1
    If you do a `Merge` on an entity that doesn't exist, you will get an error (409 I think). Not sure if you've read the REST API documentation, but I would recommend reading that: https://learn.microsoft.com/en-us/rest/api/storageservices/table-service-rest-api. It is much more elaborate. – Gaurav Mantri Jul 25 '17 at 10:05
  • I need to know for sure to use a corresponding selective `try {} catch`, they should update their documentation – serge Jul 25 '17 at 10:07
  • The error code should be 404 (and not 409). You can give it a try yourself and see what error is thrown when the entity does not exist and you're trying to perform a merge operation on that. – Gaurav Mantri Jul 25 '17 at 10:14
  • I don't really worry about the HTTP error code (that I can change), but about the .NET Exception that throws the call to the function, usually this kind of stuff is documented for each function, but not in the Azure documentation, as I can see... Thanks for the API, is interesting, but I work directly with functions in an ASP.NET Core application, so I don't use the external API – serge Jul 25 '17 at 10:35
  • 1
    So the SDK that you're using is essentially a wrapper over REST API I linked. The SDK makes REST API calls. – Gaurav Mantri Jul 25 '17 at 10:41
  • 1
    I suggest this either gets moved to chat, or new questions get posted. This has turned into a discussion in comments, with lots of extra info getting buried here. – David Makogon Jul 25 '17 at 14:22
  • Completely agree @DavidMakogon! – Gaurav Mantri Jul 25 '17 at 14:32