Mix mutations

Mix and match mutation operations such as inserting rows and deleting a column.

Code sample

C++

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

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::runtime_error(row.status().message());
  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";
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.