forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'dev/penberg/keyspace-merging/v5' from s…
…eastar-dev.git From Pekka: "This patch series converts LegacySchemaTables keyspace merging code to C++. After this series, keyspaces are actually created as demonstrated by the newly added test in cql_query_test.cc."
- Loading branch information
Showing
19 changed files
with
499 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2015 Cloudius Systems | ||
*/ | ||
|
||
#include "query-result-set.hh" | ||
|
||
namespace query { | ||
|
||
result_set_builder::result_set_builder(schema_ptr schema) | ||
: _schema{schema} | ||
{ } | ||
|
||
lw_shared_ptr<result_set> result_set_builder::build() const { | ||
return make_lw_shared<result_set>(_rows); | ||
} | ||
|
||
void result_set_builder::accept_new_partition(const partition_key& key, uint32_t row_count) | ||
{ | ||
_pkey_cells = deserialize(key); | ||
} | ||
|
||
void result_set_builder::accept_new_partition(uint32_t row_count) | ||
{ | ||
} | ||
|
||
void result_set_builder::accept_new_row(const clustering_key& key, const result_row_view& static_row, const result_row_view& row) | ||
{ | ||
auto ckey_cells = deserialize(key); | ||
auto static_cells = deserialize(static_row, true); | ||
auto regular_cells = deserialize(row, false); | ||
|
||
std::unordered_map<sstring, boost::any> cells; | ||
cells.insert(_pkey_cells.begin(), _pkey_cells.end()); | ||
cells.insert(ckey_cells.begin(), ckey_cells.end()); | ||
cells.insert(static_cells.begin(), static_cells.end()); | ||
cells.insert(regular_cells.begin(), regular_cells.end()); | ||
_rows.emplace_back(_schema, std::move(cells)); | ||
} | ||
|
||
void result_set_builder::accept_new_row(const query::result_row_view &static_row, const query::result_row_view &row) | ||
{ | ||
auto static_cells = deserialize(static_row, true); | ||
auto regular_cells = deserialize(row, false); | ||
|
||
std::unordered_map<sstring, boost::any> cells; | ||
cells.insert(_pkey_cells.begin(), _pkey_cells.end()); | ||
cells.insert(static_cells.begin(), static_cells.end()); | ||
cells.insert(regular_cells.begin(), regular_cells.end()); | ||
_rows.emplace_back(_schema, std::move(cells)); | ||
} | ||
|
||
void result_set_builder::accept_partition_end(const result_row_view& static_row) | ||
{ | ||
_pkey_cells.clear(); | ||
} | ||
|
||
std::unordered_map<sstring, boost::any> | ||
result_set_builder::deserialize(const partition_key& key) | ||
{ | ||
std::unordered_map<sstring, boost::any> cells; | ||
auto i = key.begin(*_schema); | ||
for (auto&& col : _schema->partition_key_columns()) { | ||
cells.emplace(col.name_as_text(), col.type->deserialize(*i)); | ||
++i; | ||
} | ||
return cells; | ||
} | ||
|
||
std::unordered_map<sstring, boost::any> | ||
result_set_builder::deserialize(const clustering_key& key) | ||
{ | ||
std::unordered_map<sstring, boost::any> cells; | ||
auto i = key.begin(*_schema); | ||
for (auto&& col : _schema->clustering_key_columns()) { | ||
cells.emplace(col.name_as_text(), col.type->deserialize(*i)); | ||
++i; | ||
} | ||
return cells; | ||
} | ||
|
||
std::unordered_map<sstring, boost::any> | ||
result_set_builder::deserialize(const result_row_view& row, bool is_static) | ||
{ | ||
std::unordered_map<sstring, boost::any> cells; | ||
auto i = row.iterator(); | ||
auto columns = is_static ? _schema->static_columns() : _schema->regular_columns(); | ||
for (auto &&col : columns) { | ||
if (col.is_atomic()) { | ||
auto cell = i.next_atomic_cell(); | ||
if (cell) { | ||
auto view = cell.value(); | ||
cells.emplace(col.name_as_text(), col.type->deserialize(view.value())); | ||
} | ||
} else { | ||
auto cell = i.next_collection_cell(); | ||
if (cell) { | ||
auto ctype = static_pointer_cast<collection_type_impl>(col.type); | ||
auto view = cell.value(); | ||
cells.emplace(col.name_as_text(), ctype->deserialize(view.data, serialization_format::internal())); | ||
} | ||
} | ||
} | ||
return cells; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2015 Cloudius Systems | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "query-result-reader.hh" | ||
|
||
#include "core/shared_ptr.hh" | ||
|
||
#include <experimental/optional> | ||
#include <stdexcept> | ||
|
||
#include <boost/any.hpp> | ||
|
||
namespace query { | ||
|
||
class no_such_column : public std::runtime_error { | ||
public: | ||
using runtime_error::runtime_error; | ||
}; | ||
|
||
class null_column_value : public std::runtime_error { | ||
public: | ||
using runtime_error::runtime_error; | ||
}; | ||
|
||
// Result set row is a set of cells that are associated with a row | ||
// including regular column cells, partition keys, as well as static values. | ||
class result_set_row { | ||
schema_ptr _schema; | ||
std::unordered_map<sstring, boost::any> _cells; | ||
public: | ||
result_set_row(schema_ptr schema, std::unordered_map<sstring, boost::any>&& cells) | ||
: _schema{schema} | ||
, _cells{std::move(cells)} | ||
{ } | ||
// Look up a deserialized row cell value by column name. | ||
template<typename T> | ||
std::experimental::optional<T> | ||
get(const sstring& column_name) const throw (no_such_column) { | ||
auto it = _cells.find(column_name); | ||
if (it == _cells.end()) { | ||
throw no_such_column(column_name); | ||
} | ||
if (it->second.empty()) { | ||
return std::experimental::nullopt; | ||
} | ||
return std::experimental::optional<T>{boost::any_cast<T>(it->second)}; | ||
} | ||
template<typename T> | ||
T get_nonnull(const sstring& column_name) const throw (no_such_column, null_column_value) { | ||
auto v = get<T>(column_name); | ||
if (v) { | ||
return *v; | ||
} | ||
throw null_column_value(column_name); | ||
} | ||
}; | ||
|
||
// Result set is an in-memory representation of query results in | ||
// deserialized format. To obtain a result set, use the result_set_builder | ||
// class as a visitor to query_result::consume() function. | ||
class result_set { | ||
std::vector<result_set_row> _rows; | ||
public: | ||
result_set(const std::vector<result_set_row>& rows) | ||
: _rows{std::move(rows)} | ||
{ } | ||
bool empty() const { | ||
return _rows.empty(); | ||
} | ||
const result_set_row& row(size_t idx) const throw (std::out_of_range) { | ||
if (idx >= _rows.size()) { | ||
throw std::out_of_range("no such row in result set: " + std::to_string(idx)); | ||
} | ||
return _rows[idx]; | ||
} | ||
}; | ||
|
||
// Result set builder is passed as a visitor to query_result::consume() | ||
// function. You can call the build() method to obtain a result set that | ||
// contains cells from the visited results. | ||
class result_set_builder { | ||
schema_ptr _schema; | ||
std::vector<result_set_row> _rows; | ||
std::unordered_map<sstring, boost::any> _pkey_cells; | ||
public: | ||
result_set_builder(schema_ptr schema); | ||
lw_shared_ptr<result_set> build() const; | ||
void accept_new_partition(const partition_key& key, uint32_t row_count); | ||
void accept_new_partition(uint32_t row_count); | ||
void accept_new_row(const clustering_key& key, const result_row_view& static_row, const result_row_view& row); | ||
void accept_new_row(const result_row_view &static_row, const result_row_view &row); | ||
void accept_partition_end(const result_row_view& static_row); | ||
private: | ||
std::unordered_map<sstring, boost::any> deserialize(const partition_key& key); | ||
std::unordered_map<sstring, boost::any> deserialize(const clustering_key& key); | ||
std::unordered_map<sstring, boost::any> deserialize(const result_row_view& row, bool is_static); | ||
}; | ||
|
||
} |
Oops, something went wrong.