quasardb 3.14.2.dev1__cp311-cp311-win32.whl → 3.14.2.dev3__cp311-cp311-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of quasardb might be problematic. Click here for more details.
- quasardb/CMakeLists.txt +19 -12
- quasardb/INSTALL.vcxproj +4 -0
- quasardb/__init__.py +33 -4
- quasardb/cluster.cpp +14 -1
- quasardb/cluster.hpp +114 -72
- quasardb/concepts.hpp +56 -12
- quasardb/continuous.cpp +84 -34
- quasardb/continuous.hpp +10 -7
- quasardb/convert/array.hpp +23 -6
- quasardb/convert/value.hpp +78 -7
- quasardb/date/ALL_BUILD.vcxproj +4 -4
- quasardb/date/CMakeFiles/Export/df49adab93b9e0c10c64f72458b31971/dateTargets.cmake +12 -12
- quasardb/date/CMakeFiles/generate.stamp.depend +4 -4
- quasardb/date/INSTALL.vcxproj +4 -0
- quasardb/date/dateConfigVersion.cmake +0 -5
- quasardb/date/dateTargets.cmake +3 -7
- quasardb/detail/invoke.hpp +0 -0
- quasardb/detail/retry.cpp +30 -0
- quasardb/detail/retry.hpp +147 -0
- quasardb/detail/sleep.hpp +53 -0
- quasardb/{writer.cpp → detail/writer.cpp} +68 -162
- quasardb/detail/writer.hpp +550 -0
- quasardb/error.hpp +76 -1
- quasardb/masked_array.hpp +9 -2
- quasardb/module.cpp +20 -4
- quasardb/node.hpp +17 -8
- quasardb/numpy/__init__.py +58 -10
- quasardb/object_tracker.hpp +2 -3
- quasardb/options.hpp +32 -3
- quasardb/pandas/__init__.py +59 -102
- quasardb/properties.cpp +41 -0
- quasardb/properties.hpp +85 -0
- quasardb/pybind11/ALL_BUILD.vcxproj +4 -4
- quasardb/pybind11/CMakeFiles/generate.stamp.depend +14 -14
- quasardb/pybind11/INSTALL.vcxproj +4 -0
- quasardb/qdb_api.dll +0 -0
- quasardb/quasardb.cp311-win32.pyd +0 -0
- quasardb/range-v3/ALL_BUILD.vcxproj +4 -4
- quasardb/range-v3/CMakeFiles/Export/d94ef200eca10a819b5858b33e808f5b/range-v3-targets.cmake +12 -12
- quasardb/range-v3/CMakeFiles/generate.stamp.depend +11 -11
- quasardb/range-v3/INSTALL.vcxproj +4 -0
- quasardb/range-v3/cmake_install.cmake +36 -0
- quasardb/range-v3/range-v3-config-version.cmake +0 -5
- quasardb/range-v3/range-v3-config.cmake +3 -7
- quasardb/range-v3/range.v3.headers.vcxproj +4 -4
- quasardb/reader.cpp +282 -0
- quasardb/reader.hpp +256 -0
- quasardb/table.cpp +4 -36
- quasardb/table.hpp +69 -28
- quasardb/traits.hpp +23 -0
- quasardb/writer.hpp +245 -287
- {quasardb-3.14.2.dev1.dist-info → quasardb-3.14.2.dev3.dist-info}/METADATA +7 -7
- {quasardb-3.14.2.dev1.dist-info → quasardb-3.14.2.dev3.dist-info}/RECORD +56 -50
- {quasardb-3.14.2.dev1.dist-info → quasardb-3.14.2.dev3.dist-info}/WHEEL +1 -1
- quasardb/reader/ts_row.hpp +0 -281
- quasardb/reader/ts_value.hpp +0 -245
- quasardb/table_reader.hpp +0 -220
- {quasardb-3.14.2.dev1.dist-info → quasardb-3.14.2.dev3.dist-info}/LICENSE.md +0 -0
- {quasardb-3.14.2.dev1.dist-info → quasardb-3.14.2.dev3.dist-info}/top_level.txt +0 -0
quasardb/reader.cpp
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
#include "reader.hpp"
|
|
2
|
+
#include "error.hpp"
|
|
3
|
+
#include "table.hpp"
|
|
4
|
+
#include "traits.hpp"
|
|
5
|
+
#include "convert/array.hpp"
|
|
6
|
+
#include "convert/value.hpp"
|
|
7
|
+
#include "detail/qdb_resource.hpp"
|
|
8
|
+
#include <range/v3/view/counted.hpp>
|
|
9
|
+
|
|
10
|
+
namespace qdb
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
namespace detail
|
|
14
|
+
{
|
|
15
|
+
|
|
16
|
+
/* static */ py::dict reader_data::convert(qdb_bulk_reader_table_data_t const & data)
|
|
17
|
+
{
|
|
18
|
+
py::dict ret{};
|
|
19
|
+
|
|
20
|
+
// typedef struct
|
|
21
|
+
// {
|
|
22
|
+
// qdb_size_t row_count;
|
|
23
|
+
// qdb_size_t column_count;
|
|
24
|
+
// const qdb_timespec_t * timestamps;
|
|
25
|
+
// const qdb_exp_batch_push_column_t * columns;
|
|
26
|
+
// } qdb_exp_batch_push_table_data_t;
|
|
27
|
+
|
|
28
|
+
// Convert the timestamp index, which should never contain null values
|
|
29
|
+
// and thus is *not* a masked array.
|
|
30
|
+
auto timestamps = ranges::views::counted(data.timestamps, data.row_count);
|
|
31
|
+
auto columns = ranges::views::counted(data.columns, data.column_count);
|
|
32
|
+
|
|
33
|
+
py::array idx = convert::array<qdb_timespec_t, traits::datetime64_ns_dtype>(timestamps);
|
|
34
|
+
qdb::masked_array idx_ = qdb::masked_array::masked_none(idx);
|
|
35
|
+
|
|
36
|
+
ret[py::str("$timestamp")] = idx;
|
|
37
|
+
|
|
38
|
+
for (qdb_exp_batch_push_column_t const & column : columns)
|
|
39
|
+
{
|
|
40
|
+
// typedef struct // NOLINT(modernize-use-using)
|
|
41
|
+
// {
|
|
42
|
+
// char const * name;
|
|
43
|
+
// qdb_ts_column_type_t data_type;
|
|
44
|
+
// union
|
|
45
|
+
// {
|
|
46
|
+
// const qdb_timespec_t * timestamps;
|
|
47
|
+
// const qdb_string_t * strings;
|
|
48
|
+
// const qdb_blob_t * blobs;
|
|
49
|
+
// const qdb_int_t * ints;
|
|
50
|
+
// const double * doubles;
|
|
51
|
+
// } data;
|
|
52
|
+
// } qdb_exp_batch_push_column_t;
|
|
53
|
+
|
|
54
|
+
py::str column_name{column.name};
|
|
55
|
+
|
|
56
|
+
qdb::masked_array xs;
|
|
57
|
+
switch (column.data_type)
|
|
58
|
+
{
|
|
59
|
+
case qdb_ts_column_int64:
|
|
60
|
+
xs = convert::masked_array<qdb_int_t, traits::int64_dtype>(
|
|
61
|
+
ranges::views::counted(column.data.ints, data.row_count));
|
|
62
|
+
break;
|
|
63
|
+
case qdb_ts_column_double:
|
|
64
|
+
xs = convert::masked_array<double, traits::float64_dtype>(
|
|
65
|
+
ranges::views::counted(column.data.doubles, data.row_count));
|
|
66
|
+
break;
|
|
67
|
+
case qdb_ts_column_string:
|
|
68
|
+
xs = convert::masked_array<qdb_string_t, traits::unicode_dtype>(
|
|
69
|
+
ranges::views::counted(column.data.strings, data.row_count));
|
|
70
|
+
break;
|
|
71
|
+
case qdb_ts_column_blob:
|
|
72
|
+
xs = convert::masked_array<qdb_blob_t, traits::pyobject_dtype>(
|
|
73
|
+
ranges::views::counted(column.data.blobs, data.row_count));
|
|
74
|
+
break;
|
|
75
|
+
case qdb_ts_column_timestamp:
|
|
76
|
+
xs = convert::masked_array<qdb_timespec_t, traits::datetime64_ns_dtype>(
|
|
77
|
+
ranges::views::counted(column.data.timestamps, data.row_count));
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case qdb_ts_column_symbol:
|
|
81
|
+
// This should not happen, as "symbol" is just an internal representation, and symbols
|
|
82
|
+
// are exposed to the user as strings. If this actually happens, it indicates either
|
|
83
|
+
// a bug in the bulk reader *or* a memory corruption.
|
|
84
|
+
throw qdb::not_implemented_exception(
|
|
85
|
+
"Internal error: invalid data type: symbol column type returned from bulk reader");
|
|
86
|
+
|
|
87
|
+
case qdb_ts_column_uninitialized:
|
|
88
|
+
throw qdb::not_implemented_exception(
|
|
89
|
+
"Internal error: invalid data type: unintialized column "
|
|
90
|
+
"type returned from bulk reader");
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
ret[std::move(column_name)] = std::move(xs.cast(py::return_value_policy::move));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
reader_iterator & reader_iterator::operator++()
|
|
100
|
+
{
|
|
101
|
+
if (ptr_ == nullptr)
|
|
102
|
+
{
|
|
103
|
+
// This means this is either the first invocation, or we have
|
|
104
|
+
// previously exhausted all tables in the current "fetch" and
|
|
105
|
+
// should fetch next.
|
|
106
|
+
qdb_error_t err = qdb_bulk_reader_get_data(reader_, &ptr_, batch_size_);
|
|
107
|
+
|
|
108
|
+
if (err == qdb_e_iterator_end) [[unlikely]]
|
|
109
|
+
{
|
|
110
|
+
// We have reached the end -- reset all our internal state, and make us look
|
|
111
|
+
// like the "end" iterator.
|
|
112
|
+
handle_ = nullptr;
|
|
113
|
+
reader_ = nullptr;
|
|
114
|
+
batch_size_ = 0;
|
|
115
|
+
table_count_ = 0;
|
|
116
|
+
ptr_ = nullptr;
|
|
117
|
+
n_ = 0;
|
|
118
|
+
}
|
|
119
|
+
else
|
|
120
|
+
{
|
|
121
|
+
qdb::qdb_throw_if_error(*handle_, err);
|
|
122
|
+
|
|
123
|
+
// I like assertions
|
|
124
|
+
assert(handle_ != nullptr);
|
|
125
|
+
assert(reader_ != nullptr);
|
|
126
|
+
assert(table_count_ != 0);
|
|
127
|
+
assert(ptr_ != nullptr);
|
|
128
|
+
|
|
129
|
+
n_ = 0;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
{
|
|
134
|
+
assert(ptr_ != nullptr);
|
|
135
|
+
|
|
136
|
+
if (++n_ == table_count_)
|
|
137
|
+
{
|
|
138
|
+
// We have exhausted our tables. What we will do is just "reset" our internal state
|
|
139
|
+
// to how it would be after the initial constructor, and recurse into this function,
|
|
140
|
+
// which should then just follow the regular flow above
|
|
141
|
+
qdb_release(*handle_, ptr_);
|
|
142
|
+
|
|
143
|
+
ptr_ = nullptr;
|
|
144
|
+
n_ = 0;
|
|
145
|
+
|
|
146
|
+
return this->operator++();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// At this point, we *must* have a valid state
|
|
150
|
+
assert(ptr_ != nullptr);
|
|
151
|
+
assert(n_ < table_count_);
|
|
152
|
+
|
|
153
|
+
} // if (ptr_ == nullptr)
|
|
154
|
+
return *this;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
}; // namespace detail
|
|
158
|
+
|
|
159
|
+
qdb::reader const & reader::enter()
|
|
160
|
+
{
|
|
161
|
+
// Very small scope, because we don't need any of the allocated memory after this function is
|
|
162
|
+
// finished, so we will also release memory early.
|
|
163
|
+
qdb::object_tracker::scoped_repository object_tracker{};
|
|
164
|
+
qdb::object_tracker::scoped_capture capture{object_tracker};
|
|
165
|
+
|
|
166
|
+
std::vector<qdb_bulk_reader_table_t> tables{};
|
|
167
|
+
tables.reserve(table_names_.size());
|
|
168
|
+
|
|
169
|
+
//
|
|
170
|
+
// Convert columns if applicable
|
|
171
|
+
//
|
|
172
|
+
char const ** columns{nullptr};
|
|
173
|
+
|
|
174
|
+
// If column names were provided, set them. Otherwise, it defaults to "all columns".
|
|
175
|
+
if (column_names_.empty() == false)
|
|
176
|
+
{
|
|
177
|
+
|
|
178
|
+
// Note that this particular converter copies the string and it's tracked
|
|
179
|
+
// using the object tracker.
|
|
180
|
+
//
|
|
181
|
+
// Pre-allocate the data for the columns, make sure that the memory is tracked,
|
|
182
|
+
// so we don't have to worry about memory loss.
|
|
183
|
+
columns = object_tracker::alloc<char const *>(column_names_.size() * sizeof(char const *));
|
|
184
|
+
|
|
185
|
+
for (std::size_t i = 0; i < column_names_.size(); ++i)
|
|
186
|
+
{
|
|
187
|
+
// Because the scope of `column_names_` outlives this function / scope, we don't have
|
|
188
|
+
// to copy the string, but can just directly use the .c_str() and things will work out.
|
|
189
|
+
columns[i] = column_names_.at(i).c_str();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
qdb_ts_range_t * ranges{nullptr};
|
|
194
|
+
|
|
195
|
+
if (ranges_.empty() == false)
|
|
196
|
+
{
|
|
197
|
+
// Pre-allocate the data for the columns, make sure that the memory is tracked,
|
|
198
|
+
// so we don't have to worry about memory loss.
|
|
199
|
+
ranges = object_tracker::alloc<qdb_ts_range_t>(ranges_.size() * sizeof(qdb_ts_range_t));
|
|
200
|
+
|
|
201
|
+
for (std::size_t i = 0; i < ranges_.size(); ++i)
|
|
202
|
+
{
|
|
203
|
+
// This convert::value does not allocate anything on the heap
|
|
204
|
+
ranges[i] = convert::value<py::tuple, qdb_ts_range_t>(ranges_.at(i));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// We either have columns and have the actual array set, *or* we do not have any customized
|
|
209
|
+
// columns at all.
|
|
210
|
+
// Same applies for ranges
|
|
211
|
+
assert((columns == nullptr) == (column_names_.empty() == true));
|
|
212
|
+
assert((ranges == nullptr) == (ranges_.empty() == true));
|
|
213
|
+
|
|
214
|
+
for (std::string const & table_name : table_names_)
|
|
215
|
+
{
|
|
216
|
+
tables.emplace_back(qdb_bulk_reader_table_t{
|
|
217
|
+
// because the scope of `table_name` outlives this function, we can just directly
|
|
218
|
+
// use .c_str() without any copies.
|
|
219
|
+
table_name.c_str(), //
|
|
220
|
+
columns, //
|
|
221
|
+
column_names_.size(), //
|
|
222
|
+
ranges, //
|
|
223
|
+
ranges_.size() //
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
qdb::qdb_throw_if_error(
|
|
228
|
+
*handle_, qdb_bulk_reader_fetch(*handle_, tables.data(), tables.size(), &reader_));
|
|
229
|
+
|
|
230
|
+
return *this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
void reader::close()
|
|
234
|
+
{
|
|
235
|
+
// Even though that from the API it looks like value, qdb_reader_handle_t is actually a pointer
|
|
236
|
+
// itself that needs to be released. This static assert checks for that.
|
|
237
|
+
static_assert(std::is_pointer<decltype(reader_)>());
|
|
238
|
+
|
|
239
|
+
if (reader_ != nullptr)
|
|
240
|
+
{
|
|
241
|
+
logger_.debug("closing reader");
|
|
242
|
+
qdb_release(*handle_, reader_);
|
|
243
|
+
reader_ = nullptr;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
assert(reader_ == nullptr);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
void register_reader(py::module_ & m)
|
|
250
|
+
{
|
|
251
|
+
namespace py = pybind11;
|
|
252
|
+
|
|
253
|
+
auto reader_c = py::class_<qdb::reader>{m, "Reader"};
|
|
254
|
+
|
|
255
|
+
// basic interface
|
|
256
|
+
reader_c
|
|
257
|
+
.def(py::init< //
|
|
258
|
+
qdb::handle_ptr, //
|
|
259
|
+
std::vector<std::string> const &, //
|
|
260
|
+
std::vector<std::string> const &, //
|
|
261
|
+
std::size_t, //
|
|
262
|
+
std::vector<py::tuple> const &>(), //
|
|
263
|
+
py::arg("conn"), //
|
|
264
|
+
py::arg("table_names"), //
|
|
265
|
+
py::kw_only(), //
|
|
266
|
+
py::arg("column_names") = std::vector<std::string>{}, //
|
|
267
|
+
py::arg("batch_size") = std::size_t{0}, //
|
|
268
|
+
py::arg("ranges") = std::vector<py::tuple>{} //
|
|
269
|
+
) //
|
|
270
|
+
//
|
|
271
|
+
.def("get_batch_size", &qdb::reader::get_batch_size) //
|
|
272
|
+
//
|
|
273
|
+
.def("__enter__", &qdb::reader::enter) //
|
|
274
|
+
.def("__exit__", &qdb::reader::exit) //
|
|
275
|
+
.def( //
|
|
276
|
+
"__iter__", [](qdb::reader & r) { return py::make_iterator(r.begin(), r.end()); }, //
|
|
277
|
+
py::keep_alive<0, 1>());
|
|
278
|
+
|
|
279
|
+
//
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
} // namespace qdb
|
quasardb/reader.hpp
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Official Python API
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2009-2021, quasardb SAS. All rights reserved.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* Redistribution and use in source and binary forms, with or without
|
|
9
|
+
* modification, are permitted provided that the following conditions are met:
|
|
10
|
+
*
|
|
11
|
+
* * Redistributions of source code must retain the above copyright
|
|
12
|
+
* notice, this list of conditions and the following disclaimer.
|
|
13
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
* documentation and/or other materials provided with the distribution.
|
|
16
|
+
* * Neither the name of quasardb nor the names of its contributors may
|
|
17
|
+
* be used to endorse or promote products derived from this software
|
|
18
|
+
* without specific prior written permission.
|
|
19
|
+
*
|
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY QUASARDB AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
21
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
22
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
|
|
24
|
+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
25
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
26
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
27
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
28
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
29
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
*/
|
|
31
|
+
#pragma once
|
|
32
|
+
|
|
33
|
+
#include "handle.hpp"
|
|
34
|
+
#include "logger.hpp"
|
|
35
|
+
#include "object_tracker.hpp"
|
|
36
|
+
#include <qdb/ts.h>
|
|
37
|
+
#include <unordered_map>
|
|
38
|
+
#include <vector>
|
|
39
|
+
|
|
40
|
+
namespace py = pybind11;
|
|
41
|
+
|
|
42
|
+
namespace qdb
|
|
43
|
+
{
|
|
44
|
+
|
|
45
|
+
namespace detail
|
|
46
|
+
{
|
|
47
|
+
|
|
48
|
+
using int64_column = std::vector<qdb_int_t>;
|
|
49
|
+
using double_column = std::vector<double>;
|
|
50
|
+
using timestamp_column = std::vector<qdb_timespec_t>;
|
|
51
|
+
using blob_column = std::vector<qdb_blob_t>;
|
|
52
|
+
using string_column = std::vector<qdb_string_t>;
|
|
53
|
+
|
|
54
|
+
class reader_data
|
|
55
|
+
{
|
|
56
|
+
public:
|
|
57
|
+
/**
|
|
58
|
+
* Utility function which converts table data into a vanilla dict. Currently this works well, as
|
|
59
|
+
* there isn't any additional data/state we need to keep track of --
|
|
60
|
+
*/
|
|
61
|
+
static py::dict convert(qdb_bulk_reader_table_data_t const & data);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
class reader_iterator
|
|
65
|
+
{
|
|
66
|
+
public:
|
|
67
|
+
// Default constructor, which represents the "end" of the range
|
|
68
|
+
reader_iterator() noexcept
|
|
69
|
+
: handle_{nullptr}
|
|
70
|
+
, reader_{nullptr}
|
|
71
|
+
, batch_size_{0}
|
|
72
|
+
, table_count_{0}
|
|
73
|
+
, ptr_{nullptr}
|
|
74
|
+
, n_{0}
|
|
75
|
+
{}
|
|
76
|
+
|
|
77
|
+
// Actual initialization
|
|
78
|
+
reader_iterator(
|
|
79
|
+
handle_ptr handle, qdb_reader_handle_t reader, std::size_t batch_size, std::size_t table_count)
|
|
80
|
+
: handle_{handle}
|
|
81
|
+
, reader_{reader}
|
|
82
|
+
, batch_size_{batch_size}
|
|
83
|
+
, table_count_{table_count}
|
|
84
|
+
|
|
85
|
+
, ptr_{nullptr}
|
|
86
|
+
, n_{0}
|
|
87
|
+
{
|
|
88
|
+
// Always immediately try to fetch the first batch.
|
|
89
|
+
this->operator++();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
bool operator!=(reader_iterator const & rhs) const noexcept
|
|
93
|
+
{
|
|
94
|
+
return !(*this == rhs);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
bool operator==(reader_iterator const & rhs) const noexcept
|
|
98
|
+
{
|
|
99
|
+
// This is just a sanity check: if our handle_ is null, it means basically
|
|
100
|
+
// the entire object has to be null, and this will basically represent the
|
|
101
|
+
// ".end()" iterator.
|
|
102
|
+
|
|
103
|
+
if (handle_ == nullptr)
|
|
104
|
+
{
|
|
105
|
+
assert(reader_ == nullptr);
|
|
106
|
+
assert(ptr_ == nullptr);
|
|
107
|
+
}
|
|
108
|
+
else
|
|
109
|
+
{
|
|
110
|
+
assert(reader_ != nullptr);
|
|
111
|
+
assert(ptr_ != nullptr);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Optimization: we *only* compare the pointers, we don't actually compare
|
|
115
|
+
// the data itself. This saves a bazillion comparisons, and for the purpose
|
|
116
|
+
// of iterators, we really only care whether the current iterator is at the
|
|
117
|
+
// end.
|
|
118
|
+
return (handle_ == rhs.handle_ //
|
|
119
|
+
&& reader_ == rhs.reader_ //
|
|
120
|
+
&& batch_size_ == rhs.batch_size_ //
|
|
121
|
+
&& table_count_ == rhs.table_count_ //
|
|
122
|
+
&& ptr_ == rhs.ptr_ && n_ == rhs.n_);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
reader_iterator & operator++();
|
|
126
|
+
|
|
127
|
+
py::dict operator*()
|
|
128
|
+
{
|
|
129
|
+
assert(ptr_ != nullptr);
|
|
130
|
+
assert(n_ < table_count_);
|
|
131
|
+
|
|
132
|
+
return reader_data::convert(ptr_[n_]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private:
|
|
136
|
+
qdb::handle_ptr handle_;
|
|
137
|
+
qdb_reader_handle_t reader_;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The amount of rows to fetch in one operation. This can span multiple tables.
|
|
141
|
+
*/
|
|
142
|
+
std::size_t batch_size_;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `table_count_` enables us to manage how much far we can iterate `ptr_`.
|
|
146
|
+
*/
|
|
147
|
+
std::size_t table_count_;
|
|
148
|
+
qdb_bulk_reader_table_data_t * ptr_;
|
|
149
|
+
std::size_t n_;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
}; // namespace detail
|
|
153
|
+
|
|
154
|
+
class reader
|
|
155
|
+
{
|
|
156
|
+
public:
|
|
157
|
+
using iterator = detail::reader_iterator;
|
|
158
|
+
|
|
159
|
+
public:
|
|
160
|
+
/**
|
|
161
|
+
* Tables must always be a list of actual table objects. This ensures the lifetime
|
|
162
|
+
* of any metadata inside the tables (such as its name) will always exceed that
|
|
163
|
+
* of the reader, which simplifies things a lot.
|
|
164
|
+
*/
|
|
165
|
+
reader( //
|
|
166
|
+
qdb::handle_ptr handle, //
|
|
167
|
+
std::vector<std::string> const & table_names, //
|
|
168
|
+
std::vector<std::string> const & column_names, //
|
|
169
|
+
std::size_t batch_size, //
|
|
170
|
+
std::vector<py::tuple> const & ranges) //
|
|
171
|
+
: logger_("quasardb.reader")
|
|
172
|
+
, handle_{handle}
|
|
173
|
+
, reader_{nullptr}
|
|
174
|
+
, table_names_{table_names}
|
|
175
|
+
, column_names_{column_names}
|
|
176
|
+
, batch_size_{batch_size}
|
|
177
|
+
, ranges_{ranges}
|
|
178
|
+
{}
|
|
179
|
+
|
|
180
|
+
// prevent copy because of the table object, use a unique_ptr of the batch in cluster
|
|
181
|
+
// to return the object.
|
|
182
|
+
//
|
|
183
|
+
// we prevent these copies because that is almost never what you want, and it gives us
|
|
184
|
+
// more freedom in storing a lot of data inside this object.
|
|
185
|
+
reader(const reader &) = delete;
|
|
186
|
+
reader(reader &&) = delete;
|
|
187
|
+
|
|
188
|
+
~reader()
|
|
189
|
+
{
|
|
190
|
+
close();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Convenience function for accessing the configured batch size. Returns 0 when everything should
|
|
195
|
+
* be read in a single batch.
|
|
196
|
+
*/
|
|
197
|
+
constexpr inline std::size_t get_batch_size() const noexcept
|
|
198
|
+
{
|
|
199
|
+
return batch_size_;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Opens the actual reader; this will initiatate a call to quasardb and initialize the local
|
|
204
|
+
* reader handle. If table strings are provided instead of qdb::table objects, will automatically
|
|
205
|
+
* look those up.
|
|
206
|
+
*
|
|
207
|
+
* May throw exception upon error.
|
|
208
|
+
*
|
|
209
|
+
* :NOTE(leon): We just return a reference to ourselves, but maybe we want the outer object to wrap
|
|
210
|
+
* a subclass and return that as well. Not 100% sure if that's the best way to go. This
|
|
211
|
+
* works right now and is the same approach that we take with e.g. qdb::cluster
|
|
212
|
+
*/
|
|
213
|
+
reader const & enter();
|
|
214
|
+
|
|
215
|
+
void exit(pybind11::object type, pybind11::object value, pybind11::object traceback)
|
|
216
|
+
{
|
|
217
|
+
return close();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Clean up and close. Does not require all data to be actually read.
|
|
222
|
+
*/
|
|
223
|
+
void close();
|
|
224
|
+
|
|
225
|
+
iterator begin() const
|
|
226
|
+
{
|
|
227
|
+
if (reader_ == nullptr) [[unlikely]]
|
|
228
|
+
{
|
|
229
|
+
throw qdb::uninitialized_exception{
|
|
230
|
+
"Reader not yet opened: please encapsulate calls to the reader in a `with` block, or "
|
|
231
|
+
"explicitly `open` and `close` the resource"};
|
|
232
|
+
}
|
|
233
|
+
return iterator{handle_, reader_, batch_size_, table_names_.size()};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
iterator end() const noexcept
|
|
237
|
+
{
|
|
238
|
+
return iterator{};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
private:
|
|
242
|
+
qdb::logger logger_;
|
|
243
|
+
qdb::handle_ptr handle_;
|
|
244
|
+
qdb_reader_handle_t reader_;
|
|
245
|
+
|
|
246
|
+
std::vector<std::string> table_names_;
|
|
247
|
+
std::vector<std::string> column_names_;
|
|
248
|
+
std::size_t batch_size_;
|
|
249
|
+
std::vector<py::tuple> ranges_;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
using reader_ptr = std::unique_ptr<reader>;
|
|
253
|
+
|
|
254
|
+
void register_reader(py::module_ & m);
|
|
255
|
+
|
|
256
|
+
} // namespace qdb
|
quasardb/table.cpp
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
#include "dispatch.hpp"
|
|
3
3
|
#include "metrics.hpp"
|
|
4
4
|
#include "object_tracker.hpp"
|
|
5
|
-
#include "
|
|
5
|
+
#include "reader.hpp"
|
|
6
6
|
#include "traits.hpp"
|
|
7
7
|
#include "convert/point.hpp"
|
|
8
|
+
#include <memory> // for make_unique
|
|
8
9
|
|
|
9
10
|
namespace qdb
|
|
10
11
|
{
|
|
@@ -100,42 +101,8 @@ void table::_cache_metadata() const
|
|
|
100
101
|
{
|
|
101
102
|
_ttl = std::chrono::milliseconds{metadata->ttl};
|
|
102
103
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
py::object table::reader(
|
|
106
|
-
const std::vector<std::string> & columns, py::object ranges, bool dict_mode) const
|
|
107
|
-
{
|
|
108
|
-
_handle->check_open();
|
|
109
|
-
|
|
110
|
-
auto ranges_ = qdb::convert_ranges(ranges);
|
|
111
|
-
|
|
112
|
-
std::vector<detail::column_info> c_columns;
|
|
113
104
|
|
|
114
|
-
|
|
115
|
-
{
|
|
116
|
-
// This is a kludge, because technically a table can have no columns, and we're
|
|
117
|
-
// abusing it as "no argument provided". It's a highly exceptional use case, and
|
|
118
|
-
// doesn't really have any implication in practice (we just look up twice), so it
|
|
119
|
-
// should be ok.
|
|
120
|
-
c_columns = list_columns();
|
|
121
|
-
}
|
|
122
|
-
else
|
|
123
|
-
{
|
|
124
|
-
c_columns.reserve(columns.size());
|
|
125
|
-
// This transformation can probably be optimized, but it's only invoked when constructing
|
|
126
|
-
// the reader so it's unlikely to be a performance bottleneck.
|
|
127
|
-
std::transform(std::cbegin(columns), std::cend(columns), std::back_inserter(c_columns),
|
|
128
|
-
[this](const auto & col) {
|
|
129
|
-
const auto & info = column_info_by_id(col);
|
|
130
|
-
return detail::column_info{info.type, col, info.symtable};
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (dict_mode == true
|
|
135
|
-
? py::cast(qdb::table_reader<reader::ts_dict_row>(_handle, _alias, c_columns, ranges_),
|
|
136
|
-
py::return_value_policy::move)
|
|
137
|
-
: py::cast(qdb::table_reader<reader::ts_fast_row>(_handle, _alias, c_columns, ranges_),
|
|
138
|
-
py::return_value_policy::move));
|
|
105
|
+
_shard_size = std::chrono::milliseconds{metadata->shard_size};
|
|
139
106
|
}
|
|
140
107
|
|
|
141
108
|
qdb_uint_t table::erase_ranges(const std::string & column, py::object ranges)
|
|
@@ -286,4 +253,5 @@ std::pair<pybind11::array, masked_array> table::timestamp_get_ranges(
|
|
|
286
253
|
|
|
287
254
|
return ret;
|
|
288
255
|
}
|
|
256
|
+
|
|
289
257
|
}; // namespace qdb
|