We use bytes for many different things, and it is easy to get confused as to what format the data is actually in. Fix that for atomic_cell by proving wrappers. atomic_cell::one corresponds to a bytes object holding exactly one atomic cell, and atomic_cell::view is a bytes_view to an atomic_cell. The static functions of atomic_cell itself are privatized to prevent the unwashed masses from using them on the wrong objects. Since a row entry can hold either a an atomic cell, or a collection, depending on the schema, also introduce a variant type atomic_cell_or_collection and allow the user to pick the type explicitly. Internally both are stored as bytes object.
27 lines
841 B
C++
27 lines
841 B
C++
#include "database.hh"
|
|
#include "perf.hh"
|
|
|
|
static atomic_cell::one make_atomic_cell(bytes value) {
|
|
return atomic_cell::one::make_live(0, ttl_opt{}, value);
|
|
};
|
|
|
|
int main(int argc, char* argv[]) {
|
|
auto s = make_lw_shared(schema("ks", "cf",
|
|
{{"p1", utf8_type}}, {{"c1", int32_type}}, {{"r1", int32_type}}, {}, utf8_type));
|
|
|
|
column_family cf(s);
|
|
|
|
std::cout << "Timing mutation of single column within one row...\n";
|
|
|
|
partition_key key = to_bytes("key1");
|
|
clustering_key c_key = s->clustering_key_type->decompose_value({int32_type->decompose(2)});
|
|
bytes value = int32_type->decompose(3);
|
|
|
|
time_it([&] {
|
|
mutation m(key, s);
|
|
column_definition& col = *s->get_column_definition("r1");
|
|
m.set_clustered_cell(c_key, col, make_atomic_cell(value));
|
|
cf.apply(std::move(m));
|
|
});
|
|
}
|