问题
I building a coupon system and I use bigtable.
My schema has two column - Customer ID, Coupon code
I would like to query the table to check if the customer already exists and if true to return the code and if it doesn't, modify the customer id cell with the id and to return back the code.
I saw there is an option to do it in Bigtable ReadModifyWriteRow
operator or with CheckAndMutateRow
but I not found any references.
回答1:
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.
来源:https://stackoverflow.com/questions/57914718/read-and-modify-on-same-transaction-bigtable