From 82ce8eedbde61d0cb2f00f45efb64dff14bf81f7 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Wed, 7 Dec 2016 21:55:28 +0100 Subject: [PATCH] schema: Add view_info field This patch adds a view_info optional field to the schema. It's presence indicates the schema represents a materialized view. Signed-off-by: Duarte Nunes --- schema.cc | 11 ++++++++++- schema.hh | 8 ++++++++ schema_builder.hh | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/schema.cc b/schema.cc index 737ceb313e..aa54471891 100644 --- a/schema.cc +++ b/schema.cc @@ -348,7 +348,8 @@ bool operator==(const schema& x, const schema& y) && x._raw._compaction_strategy_options == y._raw._compaction_strategy_options && x._raw._caching_options == y._raw._caching_options && x._raw._dropped_columns == y._raw._dropped_columns - && x._raw._collections == y._raw._collections; + && x._raw._collections == y._raw._collections + && x._raw._view_info == y._raw._view_info; #if 0 && Objects.equal(triggers, other.triggers) #endif @@ -463,6 +464,9 @@ std::ostream& operator<<(std::ostream& os, const schema& s) { os << c.first << " : " << c.second->name(); } os << "}"; + if (s.is_view()) { + os << ", viewInfo=" << *s.view_info(); + } os << "]"; return os; } @@ -683,6 +687,11 @@ void schema_builder::prepare_dense_schema(schema::raw_schema& raw) { } } +schema_builder& schema_builder::with_view_info(utils::UUID base_id, sstring base_name, bool include_all_columns, sstring where_clause) { + _raw._view_info = view_info(std::move(base_id), std::move(base_name), include_all_columns, std::move(where_clause)); + return *this; +} + schema_ptr schema_builder::build() { schema::raw_schema new_raw = _raw; // Copy so that build() remains idempotent. diff --git a/schema.hh b/schema.hh index 7499fedd0f..81f15cd20e 100644 --- a/schema.hh +++ b/schema.hh @@ -37,6 +37,7 @@ #include "compress.hh" #include "compaction_strategy.hh" #include "caching_options.hh" +#include "stdx.hh" using column_count_type = uint32_t; @@ -415,6 +416,7 @@ private: table_schema_version _version; std::unordered_map _dropped_columns; std::map _collections; + stdx::optional _view_info; }; raw_schema _raw; thrift_schema _thrift; @@ -623,6 +625,12 @@ public: const data_type& regular_column_name_type() const { return _raw._regular_column_name_type; } + const stdx::optional<::view_info>& view_info() const { + return _raw._view_info; + } + bool is_view() const { + return bool(_raw._view_info); + } friend std::ostream& operator<<(std::ostream& os, const schema& s); friend bool operator==(const schema&, const schema&); const column_mapping& get_column_mapping() const; diff --git a/schema_builder.hh b/schema_builder.hh index 912d865c74..b87455c195 100644 --- a/schema_builder.hh +++ b/schema_builder.hh @@ -216,6 +216,11 @@ public: void add_default_index_names(database&); + schema_builder& with_view_info(utils::UUID base_id, sstring base_name, bool include_all_columns, sstring where_clause); + schema_builder& with_view_info(const schema& base_schema, bool include_all_columns, sstring where_clause) { + return with_view_info(base_schema.id(), base_schema.cf_name(), include_all_columns, where_clause); + } + // Equivalent to with(cp).build() schema_ptr build(compact_storage cp);