From df28985295ceaa76ac2b2fac267990c763760ed3 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 22 Oct 2019 21:37:06 +0300 Subject: [PATCH] lwt: introduce cql_statment_opt_metadata cql_statement_opt_metadata is an interim node in cql (prepared) statement hierarchy parenting modification_statement and batch_statement. If there is IF condition in such statements, they return a result set, and thus have a result set metadata. The metadata itself is filled in a subsequent patch. --- cql3/cql_statement.hh | 17 +++++++++++++++++ cql3/statements/batch_statement.cc | 2 +- cql3/statements/batch_statement.hh | 2 +- cql3/statements/modification_statement.cc | 2 +- cql3/statements/modification_statement.hh | 2 +- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cql3/cql_statement.hh b/cql3/cql_statement.hh index 33874683ad..722162e022 100644 --- a/cql3/cql_statement.hh +++ b/cql3/cql_statement.hh @@ -115,4 +115,21 @@ public: } }; +// Conditional modification statements and batches +// return a result set and have metadata, while same +// statements without conditions do not. +class cql_statement_opt_metadata : public cql_statement { +protected: + // Result set metadata, may be empty for simple updates and batches + shared_ptr _metadata; +public: + using cql_statement::cql_statement; + virtual shared_ptr get_result_metadata() const override { + if (_metadata) { + return _metadata; + } + return make_empty_metadata(); + } +}; + } diff --git a/cql3/statements/batch_statement.cc b/cql3/statements/batch_statement.cc index ae8b4bf6af..b64f77381c 100644 --- a/cql3/statements/batch_statement.cc +++ b/cql3/statements/batch_statement.cc @@ -60,7 +60,7 @@ batch_statement::batch_statement(int bound_terms, type type_, std::vector statements, std::unique_ptr attrs, cql_stats& stats) - : cql_statement_no_metadata(timeout_for_type(type_)) + : cql_statement_opt_metadata(timeout_for_type(type_)) , _bound_terms(bound_terms), _type(type_), _statements(std::move(statements)) , _attrs(std::move(attrs)) , _has_conditions(boost::algorithm::any_of(_statements, [] (auto&& s) { return s.statement->has_conditions(); })) diff --git a/cql3/statements/batch_statement.hh b/cql3/statements/batch_statement.hh index eeecafc5f6..4b46b6c1f5 100644 --- a/cql3/statements/batch_statement.hh +++ b/cql3/statements/batch_statement.hh @@ -62,7 +62,7 @@ namespace statements { * A BATCH statement parsed from a CQL query. * */ -class batch_statement : public cql_statement_no_metadata { +class batch_statement : public cql_statement_opt_metadata { static logging::logger _logger; public: using type = raw::batch_statement::type; diff --git a/cql3/statements/modification_statement.cc b/cql3/statements/modification_statement.cc index ff6f11476f..c312f11561 100644 --- a/cql3/statements/modification_statement.cc +++ b/cql3/statements/modification_statement.cc @@ -74,7 +74,7 @@ modification_statement_timeout(const schema& s) { } modification_statement::modification_statement(statement_type type_, uint32_t bound_terms, schema_ptr schema_, std::unique_ptr attrs_, cql_stats& stats) - : cql_statement_no_metadata(modification_statement_timeout(*schema_)) + : cql_statement_opt_metadata(modification_statement_timeout(*schema_)) , type{type_} , _bound_terms{bound_terms} , s{schema_} diff --git a/cql3/statements/modification_statement.hh b/cql3/statements/modification_statement.hh index d536c91b4f..b1bc505a42 100644 --- a/cql3/statements/modification_statement.hh +++ b/cql3/statements/modification_statement.hh @@ -75,7 +75,7 @@ namespace raw { class modification_statement; } /* * Abstract parent class of individual modifications, i.e. INSERT, UPDATE and DELETE. */ -class modification_statement : public cql_statement_no_metadata { +class modification_statement : public cql_statement_opt_metadata { private: static thread_local const ::shared_ptr CAS_RESULT_COLUMN;