From 124802e1964a6d7bfa9cc78d16d442f642fa8cdd Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Mon, 7 Nov 2016 14:56:58 +0100 Subject: [PATCH] cql3: Add function to build view's select statement This patch adds an utility function that creates a raw select statement from a set of columns and a where clause. It is intended to be used to create the prepared select statement used by the view class. Signed-off-by: Duarte Nunes --- cql3/statements/select_statement.cc | 20 ++++++++++++++++++++ cql3/util.hh | 6 ++++++ db/view/view_definition.hh | 0 3 files changed, 26 insertions(+) delete mode 100644 db/view/view_definition.hh diff --git a/cql3/statements/select_statement.cc b/cql3/statements/select_statement.cc index e767cdb703..4b2bdc9f97 100644 --- a/cql3/statements/select_statement.cc +++ b/cql3/statements/select_statement.cc @@ -44,6 +44,7 @@ #include "transport/messages/result_message.hh" #include "cql3/selection/selection.hh" +#include "cql3/util.hh" #include "core/shared_ptr.hh" #include "query-result-reader.hh" #include "query_result_merger.hh" @@ -647,4 +648,23 @@ bool select_statement::contains_alias(::shared_ptr name) { } +namespace util { + +shared_ptr build_select_statement( + const sstring_view& cf_name, + const sstring_view& where_clause, + std::vector included_columns) { + std::ostringstream out; + out << "SELECT "; + if (included_columns.empty()) { + out << "*"; + } else { + out << join(", ", included_columns); + } + out << " FROM " << cf_name << " WHERE " << where_clause << " ALLOW FILTERING"; + return do_with_parser(out.str(), std::mem_fn(&cql3_parser::CqlParser::selectStatement)); +} + +} + } diff --git a/cql3/util.hh b/cql3/util.hh index fe1010b345..2e369a5e1a 100644 --- a/cql3/util.hh +++ b/cql3/util.hh @@ -34,6 +34,7 @@ #include "cql3/CqlParser.hpp" #include "cql3/error_collector.hh" #include "cql3/relation.hh" +#include "cql3/statements/raw/select_statement.hh" namespace cql3 { @@ -72,6 +73,11 @@ inline sstring rename_column_in_where_clause(const sstring_view& where_clause, c return relations_to_where_clause(new_relations); } +shared_ptr build_select_statement( + const sstring_view& cf_name, + const sstring_view& where_clause, + std::vector included_columns); + } // namespace util } // namespace cql3 diff --git a/db/view/view_definition.hh b/db/view/view_definition.hh deleted file mode 100644 index e69de29bb2..0000000000