forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.cc
100 lines (87 loc) · 3.46 KB
/
query.cc
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
#include "db/serializer.hh"
#include "query-request.hh"
#include "query-result.hh"
#include "to_string.hh"
#include "bytes.hh"
#include "mutation.hh"
#include "mutation_partition_serializer.hh"
namespace query {
const partition_range full_partition_range = partition_range::make_open_ended_both_sides();
std::ostream& operator<<(std::ostream& out, const partition_slice& ps) {
return out << "{"
<< "regular_cols=[" << join(", ", ps.regular_columns) << "]"
<< ", static_cols=[" << join(", ", ps.static_columns) << "]"
<< ", rows=[" << join(", ", ps.row_ranges) << "]"
<< ", options=" << sprint("%x", ps.options.mask()) // FIXME: pretty print options
<< "}";
}
std::ostream& operator<<(std::ostream& out, const read_command& r) {
return out << "read_command{"
<< "cf_id=" << r.cf_id
<< ", slice=" << r.slice << ""
<< ", limit=" << r.row_limit
<< ", timestamp=" << r.timestamp.time_since_epoch().count() << "}";
}
size_t read_command::serialized_size() const {
size_t row_range_size = serialize_int32_size;
for (auto&& i : slice.row_ranges) {
row_range_size += i.serialized_size();
}
return 2 * serialize_int64_size // cf_id
+ serialize_int32_size // row_limit
+ serialize_int32_size // timestamp
+ serialize_int64_size // slice.options
+ (slice.static_columns.size() + 1) * serialize_int32_size
+ (slice.regular_columns.size() + 1) * serialize_int32_size
+ row_range_size;
}
void read_command::serialize(bytes::iterator& out) const {
serialize_int64(out, cf_id.get_most_significant_bits());
serialize_int64(out, cf_id.get_least_significant_bits());
serialize_int32(out, row_limit);
serialize_int32(out, timestamp.time_since_epoch().count());
serialize_int64(out, slice.options.mask());
serialize_int32(out, slice.static_columns.size());
for(auto i : slice.static_columns) {
serialize_int32(out, i);
}
serialize_int32(out, slice.regular_columns.size());
for(auto i : slice.regular_columns) {
serialize_int32(out, i);
}
serialize_int32(out, slice.row_ranges.size());
for (auto&& i : slice.row_ranges) {
i.serialize(out);
}
}
read_command read_command::deserialize(bytes_view& v) {
auto msb = read_simple<int64_t>(v);
auto lsb = read_simple<int64_t>(v);
utils::UUID uuid(msb, lsb);
uint32_t row_limit = read_simple<int32_t>(v);
auto timestamp = gc_clock::time_point(gc_clock::duration(read_simple<int32_t>(v)));
partition_slice::option_set options = partition_slice::option_set::from_mask(read_simple<int64_t>(v));
uint32_t size = read_simple<uint32_t>(v);
std::vector<column_id> static_columns;
static_columns.reserve(size);
while(size--) {
static_columns.push_back(read_simple<uint32_t>(v));
};
size = read_simple<uint32_t>(v);
std::vector<column_id> regular_columns;
regular_columns.reserve(size);
while(size--) {
regular_columns.push_back(read_simple<uint32_t>(v));
};
size = read_simple<uint32_t>(v);
std::vector<clustering_range> row_ranges;
row_ranges.reserve(size);
while(size--) {
row_ranges.emplace_back(clustering_range::deserialize(v));
};
return read_command(std::move(uuid), partition_slice(std::move(row_ranges), std::move(static_columns), std::move(regular_columns), options), row_limit, timestamp);
}
}