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 <duarte@scylladb.com>
This commit is contained in:
Duarte Nunes
2016-11-07 14:56:58 +01:00
parent 088dfdb108
commit 124802e196
3 changed files with 26 additions and 0 deletions

View File

@@ -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<column_identifier> name) {
}
namespace util {
shared_ptr<cql3::statements::raw::select_statement> build_select_statement(
const sstring_view& cf_name,
const sstring_view& where_clause,
std::vector<sstring_view> 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));
}
}
}

View File

@@ -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<cql3::statements::raw::select_statement> build_select_statement(
const sstring_view& cf_name,
const sstring_view& where_clause,
std::vector<sstring_view> included_columns);
} // namespace util
} // namespace cql3