調用BatchWriteRow介面批量插入、修改或刪除一個或多個表中的若干行資料。
BatchWriteRow操作可視為多個PutRow、UpdateRow、DeleteRow操作的集合。各個操作獨立執行,獨立返回結果,獨立計算服務能力單元。
與執行大量的單行寫操作相比,使用BatchWriteRow操作可以有效減少請求的回應時間,提高資料的寫入速率。
請求訊息結構
message BatchWriteRowRequest {
repeated TableInBatchWriteRowRequest tables = 1;
}
參數 | 類型 | 是否必需 | 描述 |
---|---|---|---|
tables | TableInBatchWriteRowRequest | 是 | 指定了需要要執行寫操作的行資訊。
以下情況都會返回整體錯誤:
|
響應訊息結構
说明 BatchWriteRow操作可能會在行層級部分失敗,此時返回的HTTP狀態代碼仍為 200。應用程式必須對RowInBatchWriteRowResponse中的error進行檢查,確認每一行的執行結果並進行相應的處理。
message BatchWriteRowResponse {
repeated TableInBatchWriteRowResponse tables = 1;
}
參數 | 類型 | 描述 |
---|---|---|
tables | TableInBatchWriteRowResponse | 對應了每個table下各操作的響應資訊,包括是否成功執行、錯誤碼和消耗的服務能力單元。
響應訊息中TableInBatchWriteRowResponse對象的順序與BatchWriteRowRequest中的TableInBatchWriteRowRequest對象的順序相同;每個TableInBatchWriteRowRequest中put_rows、update_rows、delete_rows包含的RowInBatchWriteRowResponse對象的順序分別與TableInBatchWriteRowRequest中put_rows、update_rows、delete_rows包含的PutRowInBatchWriteRowRequest、UpdateRowInBatchWriteRowRequest和DeleteRowInBatchWriteRowRequest對象的順序相同。 如果某行讀取失敗,則該行所對應的RowInBatchWriteRowResponse中is_ok將為false。 |
使用SDK
您可以使用如下語言的SDK批量寫入資料。
服務能力單元消耗
- 如果本次操作整體失敗,則不消耗任何服務能力單元。
- 如果請求逾時,結果未定義,則服務能力單元有可能被消耗,也可能未被消耗。
- 其他情況將每個PutRowInBatchWriteRowRequest、UpdateRowInBatchWriteRowRequestDelete、RowInBatchWriteRowRequest依次視作相對應的寫操作獨立計算讀寫服務能力單元。更多資訊,請參見PutRow服務能力單元消耗,UpdateRow服務能力單元消耗和DeleteRow服務能力單元消耗。