混合变更

混合和匹配变更操作,例如插入行和删除列。

代码示例

C++

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 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 示例浏览器