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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* include/query/pointlookup.h
*
* Copyright (C) 2024 Douglas B. Rumbaugh <drumbaugh@psu.edu>
*
* Distributed under the Modified BSD License.
*
* A query class for point lookup operations.
*
* TODO: Currently, this only supports point lookups for unique keys (which
* is the case for the trie that we're building this to use). It would be
* pretty straightforward to extend it to return *all* records that match
* the search_key (including tombstone cancellation--it's invertible) to
* support non-unique indexes, or at least those implementing
* lower_bound().
*/
#pragma once
#include "framework/QueryRequirements.h"
namespace de {
namespace pl {
template <ShardInterface S> class Query {
typedef typename S::RECORD R;
public:
struct Parameters {
decltype(R::key) search_key;
};
struct LocalQuery {
Parameters global_parms;
};
struct LocalQueryBuffer {
BufferView<R> *buffer;
Parameters global_parms;
};
typedef std::vector<Wrapped<R>> LocalResultType;
typedef std::vector<R> ResultType;
constexpr static bool EARLY_ABORT = true;
constexpr static bool SKIP_DELETE_FILTER = true;
static LocalQuery *local_preproc(S *shard, Parameters *parms) {
auto query = new LocalQuery();
query->global_parms = *parms;
return query;
}
static LocalQueryBuffer *local_preproc_buffer(BufferView<R> *buffer,
Parameters *parms) {
auto query = new LocalQueryBuffer();
query->buffer = buffer;
query->global_parms = *parms;
return query;
}
static void distribute_query(Parameters *parms,
std::vector<LocalQuery *> const &local_queries,
LocalQueryBuffer *buffer_query) {
return;
}
static LocalResultType local_query(S *shard, LocalQuery *query) {
LocalResultType result;
auto r = shard->point_lookup({query->global_parms.search_key, 0});
if (r) {
result.push_back(*r);
}
return result;
}
static LocalResultType local_query_buffer(LocalQueryBuffer *query) {
LocalResultType result;
for (size_t i = 0; i < query->buffer->get_record_count(); i++) {
auto rec = query->buffer->get(i);
if (rec->rec.key == query->global_parms.search_key) {
result.push_back(*rec);
return result;
}
}
return result;
}
static void
combine(std::vector<LocalResultType> const &local_results,
Parameters *parms, ResultType &output) {
for (auto r : local_results) {
if (r.size() > 0) {
if (r[0].is_deleted() || r[0].is_tombstone()) {
return;
}
output.push_back(r[0].rec);
return;
}
}
}
static bool repeat(Parameters *parms, ResultType &output,
std::vector<LocalQuery *> const &local_queries,
LocalQueryBuffer *buffer_query) {
return false;
}
};
} // namespace pl
} // namespace de
|