Mutationen vermischen

Mutationsvorgänge kombinieren und abgleichen, z. B. Zeilen einfügen und eine Spalte löschen

Codebeispiel

C++

Informationen zum Installieren und Verwenden der Clientbibliothek für Bigtable finden Sie unter Bigtable-Clientbibliotheken.

Richten Sie Standardanmeldedaten für Anwendungen ein, um sich bei Bigtable zu authentifizieren. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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";
}

Nächste Schritte

Informationen zum Suchen und Filtern von Codebeispielen für andere Google Cloud-Produkte finden Sie im Google Cloud-Beispielbrowser.