From 2853fcd5c55f577a64b4096aa6187edf5ad5e2c3 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 27 May 2015 18:02:58 -0400 Subject: [PATCH] sstables: write collections Signed-off-by: Glauber Costa --- sstables/sstables.cc | 15 ++++++++++++++- sstables/sstables.hh | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sstables/sstables.cc b/sstables/sstables.cc index 0cb956ab35..5678ec1354 100644 --- a/sstables/sstables.cc +++ b/sstables/sstables.cc @@ -1037,6 +1037,18 @@ void sstable::write_range_tombstone(file_writer& out, const composite& clusterin write(out, deletion_time, timestamp).get(); } +void sstable::write_collection(file_writer& out, const composite& clustering_key, const column_definition& cdef, collection_mutation::view collection) { + + auto t = static_pointer_cast(cdef.type); + auto mview = t->deserialize_mutation_form(collection); + const bytes& column_name = cdef.name(); + write_range_tombstone(out, clustering_key, { bytes_view(column_name) }, mview.tomb); + for (auto& cp: mview.cells) { + write_column_name(out, clustering_key, { column_name, cp.first }); + write_cell(out, cp.second); + } +} + // write_datafile_clustered_row() is about writing a clustered_row to data file according to SSTables format. // clustered_row contains a set of cells sharing the same clustering key. void sstable::write_clustered_row(file_writer& out, schema_ptr schema, const rows_entry& clustered_row) { @@ -1053,7 +1065,8 @@ void sstable::write_clustered_row(file_writer& out, schema_ptr schema, const row // non atomic cell isn't supported yet. atomic cell maps to a single trift cell. // non atomic cell maps to multiple trift cell, e.g. collection. if (!column_definition.is_atomic()) { - fail(unimplemented::cause::NONATOMIC); + write_collection(out, clustering_key, column_definition, value.second.as_collection_mutation()); + return; } assert(column_definition.is_regular()); atomic_cell_view cell = value.second.as_atomic_cell(); diff --git a/sstables/sstables.hh b/sstables/sstables.hh index d93939d5e9..a3d7faf94b 100644 --- a/sstables/sstables.hh +++ b/sstables/sstables.hh @@ -292,6 +292,7 @@ private: void write_cell(file_writer& out, atomic_cell_view cell); void write_column_name(file_writer& out, const composite& clustering_key, const std::vector& column_names, composite_marker m = composite_marker::none); void write_range_tombstone(file_writer& out, const composite& clustering_prefix, std::vector suffix, const tombstone t); + void write_collection(file_writer& out, const composite& clustering_key, const column_definition& cdef, collection_mutation::view collection); public: // Allow the test cases from sstable_test.cc to test private methods. We use // a placeholder to avoid cluttering this class too much. The sstable_test class