diff --git a/database.cc b/database.cc index ea7e82eeb9..4f336c758e 100644 --- a/database.cc +++ b/database.cc @@ -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)) { +} diff --git a/database.hh b/database.hh index c52d968b61..ae5cf6fd91 100644 --- a/database.hh +++ b/database.hh @@ -67,16 +67,28 @@ public: } }; -struct row { - std::vector 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; +struct row; +struct paritition; +struct column_family; + +struct row { + std::vector cells; +}; struct partition { + explicit partition(column_family& cf); row static_columns; // row key within partition -> row - std::map rows; + std::map 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 partition_key; std::vector clustering_key; std::vector column_defs; std::unordered_map column_names; // partition key -> partition - std::map partitions; + std::map partitions; }; struct keyspace { diff --git a/thrift/handler.cc b/thrift/handler.cc index 029c354fe7..1a2fd4d120 100644 --- a/thrift/handler.cc +++ b/thrift/handler.cc @@ -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); }