db: store keys and values as serialized bytes, not boost::any

While less efficient, it's similar to what origin does, so will be easier
to follow.
This commit is contained in:
Avi Kivity
2014-12-25 13:01:16 +02:00
parent ab26aef422
commit de349cd205
3 changed files with 33 additions and 6 deletions

View File

@@ -90,3 +90,14 @@ data_type ascii_type(new string_type_impl("ascii"));
data_type blob_type(new blob_type_impl);
data_type varchar_type(new string_type_impl("varchar"));
data_type text_type(new string_type_impl("text"));
partition::partition(column_family& cf)
: rows(key_compare(cf.clustering_key_type)) {
}
column_family::column_family(data_type partition_key_type,
data_type clustering_key_type)
: partition_key_type(std::move(partition_key_type))
, clustering_key_type(std::move(clustering_key_type))
, partitions(key_compare(partition_key_type)) {
}

View File

@@ -67,16 +67,28 @@ public:
}
};
struct row {
std::vector<boost::any> cells;
class key_compare {
data_type _type;
public:
key_compare(data_type type) : _type(type) {}
bool operator()(const bytes& v1, const bytes& v2) const {
return _type.less(v1, v2);
}
};
using key_compare = std::function<bool (const boost::any&, const boost::any&)>;
struct row;
struct paritition;
struct column_family;
struct row {
std::vector<bytes> cells;
};
struct partition {
explicit partition(column_family& cf);
row static_columns;
// row key within partition -> row
std::map<boost::any, row, key_compare> rows;
std::map<bytes, row, key_compare> rows;
};
// FIXME: add missing types
@@ -93,13 +105,16 @@ struct column_definition {
};
struct column_family {
column_family(data_type partition_key_type, data_type clustering_key_type);
// primary key = paritition key + clustering_key
data_type partition_key_type;
data_type clustering_key_type;
std::vector<column_definition> partition_key;
std::vector<column_definition> clustering_key;
std::vector<column_definition> column_defs;
std::unordered_map<sstring, unsigned> column_names;
// partition key -> partition
std::map<boost::any, partition, key_compare> partitions;
std::map<bytes, partition, key_compare> partitions;
};
struct keyspace {

View File

@@ -241,7 +241,7 @@ public:
}
keyspace& ks = _db.keyspaces[ks_def.name];
for (const CfDef& cf_def : ks_def.cf_defs) {
column_family& cf = ks.column_families[cf_def.name];
column_family cf(blob_type, blob_type);
// FIXME: look at key_alias and key_validator first
cf.partition_key.push_back(column_definition{"key", blob_type});
// FIXME: guess clustering keys
@@ -252,6 +252,7 @@ public:
blob_type,
});
}
ks.column_families.emplace(cf_def.name, std::move(cf));
}
cob(schema_id);
}