diff --git a/atomic_cell.hh b/atomic_cell.hh index 5b46ff78fa..62bd5c8db8 100644 --- a/atomic_cell.hh +++ b/atomic_cell.hh @@ -9,6 +9,7 @@ #include "tombstone.hh" #include "gc_clock.hh" #include +#include template static inline @@ -223,6 +224,7 @@ public: collection_mutation::view as_collection_mutation() const { return collection_mutation::view{_data}; } + friend std::ostream& operator<<(std::ostream&, const atomic_cell_or_collection&); }; class column_definition; diff --git a/database.cc b/database.cc index 9afcae83db..ad1fef1446 100644 --- a/database.cc +++ b/database.cc @@ -720,14 +720,6 @@ bool column_definition::is_compact_value() const { return false; } -std::ostream& operator<<(std::ostream& os, const mutation& m) { - return fprint(os, "{mutation: schema %p key %s data %s}", m.schema.get(), static_cast(m.key), m.p); -} - -std::ostream& operator<<(std::ostream& os, const mutation_partition& mp) { - return fprint(os, "{mutation_partition: ...}"); -} - boost::iterator_range mutation_partition::range(const schema& schema, const query::range& r) const { if (r.is_full()) { @@ -970,6 +962,51 @@ database::query(const query::read_command& cmd) { } } +std::ostream& operator<<(std::ostream& out, const atomic_cell_or_collection& c) { + return out << to_hex(c._data); +} + +void print_partition(std::ostream& out, const schema& s, const mutation_partition& mp) { + out << "{rows={\n"; + for (auto&& e : mp.range(s, query::range())) { + out << e.key() << " => "; + for (auto&& cell_e : e.row().cells) { + out << cell_e.first << ":"; + out << cell_e.second << " "; + } + out << "\n"; + } + out << "}}"; +} + +std::ostream& operator<<(std::ostream& os, const mutation& m) { + fprint(os, "{mutation: schema %p key %s data ", m.schema.get(), static_cast(m.key)); + print_partition(os, *m.schema, m.p); + os << "}"; + return os; +} + +std::ostream& operator<<(std::ostream& out, const column_family& cf) { + out << "{\n"; + for (auto&& e : cf.partitions) { + out << e.first << " => "; + print_partition(out, *cf._schema, e.second); + out << "\n"; + } + out << "}"; + return out; +} + +std::ostream& operator<<(std::ostream& out, const database& db) { + out << "{\n"; + for (auto&& e : db._column_families) { + auto&& cf = e.second; + out << "(" << e.first.to_sstring() << ", " << cf._schema->cf_name << ", " << cf._schema->ks_name << "): " << cf << "\n"; + } + out << "}"; + return out; +} + namespace db { std::ostream& operator<<(std::ostream& os, db::consistency_level cl) { diff --git a/database.hh b/database.hh index 7b5ed38077..bdcc065977 100644 --- a/database.hh +++ b/database.hh @@ -326,6 +326,7 @@ public: } unsigned shard_of(const dht::token& t); future> query(const query::read_command& cmd); + friend std::ostream& operator<<(std::ostream& out, const database& db); }; // FIXME: stub diff --git a/query.hh b/query.hh index aeae470870..ffb57f6fa3 100644 --- a/query.hh +++ b/query.hh @@ -40,6 +40,7 @@ public: , _end() , _singular(true) { } + range() : range({}, {}) {} public: static range make(bound start, bound end) { return range({std::move(start)}, {std::move(end)});