混合變異

混用異動作業,例如插入資料列和刪除資料欄。

程式碼範例

C++

如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱這篇文章

如要向 Bigtable 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::Status;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& key, std::string const& family,
   std::string const& old_name, std::string const& new_name) {
  StatusOr<std::pair<bool, cbt::Row>> row =
      table.ReadRow(key, cbt::Filter::ColumnName(family, old_name));

  if (!row) throw std::move(row).status();
  if (!row->first) throw std::runtime_error("Cannot find row " + key);

  cbt::SingleRowMutation mutation(key);
  for (auto const& cell : row->second.cells()) {
    // Create a new cell
    auto timestamp_in_milliseconds =
        std::chrono::duration_cast<std::chrono::milliseconds>(
            cell.timestamp());
    mutation.emplace_back(cbt::SetCell(family, new_name,
                                       timestamp_in_milliseconds,
                                       std::move(cell).value()));
  }
  mutation.emplace_back(cbt::DeleteFromColumn("fam", old_name));

  google::cloud::Status status = table.Apply(std::move(mutation));
  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Row successfully updated\n";
}

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器