pythongoogle-cloud-platformbigtablegoogle-cloud-bigtable

Read And Modify On Same Transaction - Bigtable


I am building a coupon system and I am using Bigtable.

My schema has two columns - Customer ID and Coupon code.

I would like to query the table to check if the customer already exists and if it is true, return the code and if it is false, modify the Customer ID cell with the ID and return back the code.

I saw there is an option to do it in Bigtable ReadModifyWriteRow operator or with CheckAndMutateRow but I have not found any references.


Solution

  • Google has API documentation for Bigtable and Python available here. This shows you all the available methods and the source code that they refer to, so you can easily and more effectively use and understand the usage.

    ReadModifyWriteRow appends as bytes or increments data in an existing cell in a row.

    CheckAndMutateRow checks if a filter matched and then applies 2 sets of mutations. These are “true mutations” and “false mutations”.

    You can use if statements in order to achieve the usage that you wish.

    You can read about CheckAndMutateRow conditional requests, and there are also code samples available.