From 986ab6034c32d67a0ffbea500501e8c39f1d17fa Mon Sep 17 00:00:00 2001 From: Piotr Dulikowski Date: Thu, 28 Jul 2022 18:51:14 +0200 Subject: [PATCH] db/view: add clustering_or_static_row Adds a `clustering_or_static_row`, which is a common, immutable representation of either a static or clustering row. It will allow to handle view update generation based on static or clustering rows in a uniform way. --- db/view/view.cc | 14 ++++++++++++++ db/view/view.hh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/db/view/view.cc b/db/view/view.cc index 4746b80db0..a52d6e385b 100644 --- a/db/view/view.cc +++ b/db/view/view.cc @@ -233,6 +233,20 @@ bool view_info::has_base_non_pk_columns_in_view_pk() const { return _base_info->has_base_non_pk_columns_in_view_pk; } +clustering_row db::view::clustering_or_static_row::as_clustering_row(const schema& s) const { + if (!is_clustering_row()) { + on_internal_error(vlogger, "Tried to interpret a static row as a clustering row"); + } + return clustering_row(*_key, tomb(), marker(), row(s, column_kind::regular_column, cells())); +} + +static_row db::view::clustering_or_static_row::as_static_row(const schema& s) const { + if (!is_static_row()) { + on_internal_error(vlogger, "Tried to interpret a clustering row as a static row"); + } + return static_row(s, cells()); +} + namespace db { namespace view { diff --git a/db/view/view.hh b/db/view/view.hh index 831edbce0b..700c2e62d5 100644 --- a/db/view/view.hh +++ b/db/view/view.hh @@ -80,6 +80,46 @@ struct view_and_base { base_info_ptr base; }; +// An immutable representation of a clustering or static row of the base table. +struct clustering_or_static_row { +private: + std::optional _key; + deletable_row _row; + +public: + explicit clustering_or_static_row(clustering_row&& cr) + : _key(std::move(cr.key())) + , _row(std::move(cr).as_deletable_row()) + {} + + explicit clustering_or_static_row(static_row&& sr) + : _key() + , _row(row_tombstone(), row_marker(), std::move(sr.cells())) + {} + + bool is_static_row() const { return !_key.has_value(); } + bool is_clustering_row() const { return _key.has_value(); } + + const std::optional& key() const { return _key; } + + row_tombstone tomb() const { return _row.deleted_at(); } + const row_marker& marker() const { return _row.marker(); } + const row& cells() const { return _row.cells(); } + + bool empty() const { return _row.empty(); } + bool is_live(const schema& s, tombstone base_tombstone = tombstone(), gc_clock::time_point now = gc_clock::time_point::min()) const { + return _row.is_live(s, column_kind(), base_tombstone, now); + } + + column_kind column_kind() const { + return _key.has_value() + ? column_kind::regular_column : column_kind::static_column; + } + + clustering_row as_clustering_row(const schema& s) const; + static_row as_static_row(const schema& s) const; +}; + /** * Whether the view filter considers the specified partition key. *