-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathschema_upgrader.hh
74 lines (69 loc) · 2.45 KB
/
schema_upgrader.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (C) 2017 ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "mutation_fragment.hh"
#include "converting_mutation_partition_applier.hh"
// A StreamedMutationTransformer which transforms the stream to a different schema
class schema_upgrader {
schema_ptr _prev;
schema_ptr _new;
private:
row transform(row&& r, column_kind kind) {
row new_row;
r.for_each_cell([&] (column_id id, atomic_cell_or_collection& cell) {
const column_definition& col = _prev->column_at(kind, id);
const column_definition* new_col = _new->get_column_definition(col.name());
if (new_col) {
converting_mutation_partition_applier::append_cell(new_row, kind, *new_col, col, std::move(cell));
}
});
return new_row;
}
public:
schema_upgrader(schema_ptr s)
: _new(std::move(s))
{ }
schema_ptr operator()(schema_ptr old) {
_prev = std::move(old);
return _new;
}
mutation_fragment consume(static_row&& row) {
return mutation_fragment(static_row(transform(std::move(row.cells()), column_kind::static_column)));
}
mutation_fragment consume(clustering_row&& row) {
return mutation_fragment(clustering_row(row.key(), row.tomb(), row.marker(),
transform(std::move(row.cells()), column_kind::regular_column)));
}
mutation_fragment consume(range_tombstone&& rt) {
return std::move(rt);
}
mutation_fragment consume(partition_start&& ph) {
return std::move(ph);
}
mutation_fragment consume(partition_end&& eop) {
return std::move(eop);
}
mutation_fragment operator()(mutation_fragment&& mf) {
return std::move(mf).consume(*this);
}
};
GCC6_CONCEPT(
static_assert(StreamedMutationTranformer<schema_upgrader>());
)