quasardb 3.14.2.dev0__cp37-cp37m-win_amd64.whl → 3.14.2.dev2__cp37-cp37m-win_amd64.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 +30 -13
- quasardb/INSTALL.vcxproj +4 -0
- quasardb/__init__.py +33 -4
- quasardb/cluster.cpp +7 -1
- quasardb/cluster.hpp +111 -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/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.cp37-win_amd64.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.dev0.dist-info → quasardb-3.14.2.dev2.dist-info}/METADATA +6 -6
- {quasardb-3.14.2.dev0.dist-info → quasardb-3.14.2.dev2.dist-info}/RECORD +55 -49
- {quasardb-3.14.2.dev0.dist-info → quasardb-3.14.2.dev2.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.dev0.dist-info → quasardb-3.14.2.dev2.dist-info}/LICENSE.md +0 -0
- {quasardb-3.14.2.dev0.dist-info → quasardb-3.14.2.dev2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
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 "../error.hpp"
|
|
34
|
+
#include <chrono>
|
|
35
|
+
|
|
36
|
+
namespace qdb::detail
|
|
37
|
+
{
|
|
38
|
+
|
|
39
|
+
struct retry_options
|
|
40
|
+
{
|
|
41
|
+
qdb::logger logger_;
|
|
42
|
+
|
|
43
|
+
// how many retries are left. 0 means no retries
|
|
44
|
+
std::size_t retries_left;
|
|
45
|
+
|
|
46
|
+
// delay for the next retry
|
|
47
|
+
std::chrono::milliseconds delay;
|
|
48
|
+
|
|
49
|
+
// factor by which delay is increased every retry
|
|
50
|
+
std::size_t exponent;
|
|
51
|
+
|
|
52
|
+
// random jitter added/removed to delay_. Jitter of 0.1 means that 10% is automatically
|
|
53
|
+
// added or removed from delay_
|
|
54
|
+
double jitter;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Retry options constructor
|
|
58
|
+
*/
|
|
59
|
+
retry_options(std::size_t retries = 3,
|
|
60
|
+
std::chrono::milliseconds delay = std::chrono::milliseconds{3000},
|
|
61
|
+
std::size_t exponent = 2,
|
|
62
|
+
double jitter = 0.1)
|
|
63
|
+
: logger_("quasardb.detail.retry")
|
|
64
|
+
, retries_left{retries}
|
|
65
|
+
, delay{delay}
|
|
66
|
+
, exponent{exponent}
|
|
67
|
+
, jitter{jitter}
|
|
68
|
+
{}
|
|
69
|
+
|
|
70
|
+
static inline retry_options from_kwargs(py::kwargs args)
|
|
71
|
+
{
|
|
72
|
+
if (args.contains("retries") == false)
|
|
73
|
+
{
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
auto retries = args["retries"];
|
|
78
|
+
|
|
79
|
+
// We're going to assume that retries is an actual RetryOptions class, because
|
|
80
|
+
// our Numpy and Pandas adapters always coerce it to that type. By making this
|
|
81
|
+
// assumption, we can slightly optimize this code path.
|
|
82
|
+
//
|
|
83
|
+
// By providing an explicit RetryOptions object is also the only way to fine-tune
|
|
84
|
+
// other parameters.
|
|
85
|
+
|
|
86
|
+
try
|
|
87
|
+
{
|
|
88
|
+
return retries.cast<retry_options>();
|
|
89
|
+
}
|
|
90
|
+
catch (py::cast_error const & /*e*/)
|
|
91
|
+
{
|
|
92
|
+
// For convenience, we also give the user the choice to just provide `retries`
|
|
93
|
+
// as an integer, in which case we'll assume this is the number of retries the
|
|
94
|
+
// user wants to perform.
|
|
95
|
+
//
|
|
96
|
+
// In all likelihood, this is the only parameter the user will want to tune.
|
|
97
|
+
return {retries.cast<std::size_t>()};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
inline constexpr bool has_next() const noexcept
|
|
102
|
+
{
|
|
103
|
+
return retries_left > 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns new object, with `retries_left_` and `delay_` adjusted accordingly.
|
|
108
|
+
*/
|
|
109
|
+
inline retry_options next() const
|
|
110
|
+
{
|
|
111
|
+
if (has_next() == false) [[unlikely]]
|
|
112
|
+
{
|
|
113
|
+
throw qdb::out_of_bounds_exception{
|
|
114
|
+
"RetryOptions.next() called but retries already exhausted."};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
assert(has_next() == true);
|
|
118
|
+
|
|
119
|
+
return retry_options{retries_left - 1, delay * exponent, exponent, jitter};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns true if we have retries left and the error is retryable.
|
|
124
|
+
*/
|
|
125
|
+
inline constexpr bool should_retry(qdb_error_t e) const noexcept
|
|
126
|
+
{
|
|
127
|
+
// We check for `is_retryable` first, because in all likelihood e is qdb_e_ok
|
|
128
|
+
return retry_options::is_retryable(e) && has_next();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static constexpr bool is_retryable(qdb_error_t e) noexcept
|
|
132
|
+
{
|
|
133
|
+
switch (e)
|
|
134
|
+
{
|
|
135
|
+
case qdb_e_async_pipe_full:
|
|
136
|
+
case qdb_e_try_again:
|
|
137
|
+
return true;
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
return false;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
void register_retry_options(py::module_ & m);
|
|
146
|
+
|
|
147
|
+
}; // namespace qdb::detail
|
|
@@ -0,0 +1,53 @@
|
|
|
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 "../concepts.hpp"
|
|
34
|
+
#include <chrono>
|
|
35
|
+
|
|
36
|
+
namespace qdb::detail
|
|
37
|
+
{
|
|
38
|
+
|
|
39
|
+
template <typename Duration = std::chrono::milliseconds>
|
|
40
|
+
struct default_sleep_strategy
|
|
41
|
+
{
|
|
42
|
+
using duration_t = Duration;
|
|
43
|
+
|
|
44
|
+
static void sleep(duration_t const & delay)
|
|
45
|
+
{
|
|
46
|
+
std::this_thread::sleep_for(delay);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
static_assert(qdb::concepts::sleep_strategy<default_sleep_strategy<>>);
|
|
51
|
+
static_assert(qdb::concepts::sleep_strategy<default_sleep_strategy<std::chrono::seconds>>);
|
|
52
|
+
|
|
53
|
+
}; // namespace qdb::detail
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#include "writer.hpp"
|
|
2
|
+
#include "../convert/array.hpp"
|
|
2
3
|
#include "concepts.hpp"
|
|
3
4
|
#include "dispatch.hpp"
|
|
4
|
-
#include "metrics.hpp"
|
|
5
5
|
#include "numpy.hpp"
|
|
6
|
+
#include "retry.hpp"
|
|
6
7
|
#include "traits.hpp"
|
|
7
|
-
#include "convert/array.hpp"
|
|
8
8
|
|
|
9
9
|
namespace qdb::detail
|
|
10
10
|
{
|
|
@@ -123,10 +123,10 @@ struct fill_column_dispatch
|
|
|
123
123
|
{
|
|
124
124
|
qdb_exp_batch_push_column_t ret{};
|
|
125
125
|
|
|
126
|
-
ret.name =
|
|
126
|
+
ret.name = nullptr;
|
|
127
127
|
ret.data_type = ctype;
|
|
128
128
|
|
|
129
|
-
// We swap the pointer inside the `
|
|
129
|
+
// We swap the pointer inside the `qdb_exp_batch_push_column_t` with the pointer
|
|
130
130
|
// to the data as it is inside the `any_column`.
|
|
131
131
|
//
|
|
132
132
|
// This works, because all these `any_column`'s lifecycle is scoped to the
|
|
@@ -191,7 +191,7 @@ std::vector<qdb_exp_batch_push_column_t> const & staged_table::prepare_columns()
|
|
|
191
191
|
// XXX(leon): reuses lifecycle of _column_infos[index], which *should* be fine,
|
|
192
192
|
// but ensuring we take a reference is super important here!
|
|
193
193
|
std::string const & column_name = _column_infos[index].name;
|
|
194
|
-
column.name =
|
|
194
|
+
column.name = column_name.c_str();
|
|
195
195
|
|
|
196
196
|
#ifndef NDEBUG
|
|
197
197
|
// Symbol column is actually string data
|
|
@@ -222,7 +222,7 @@ void staged_table::prepare_batch(qdb_exp_batch_push_mode_t mode,
|
|
|
222
222
|
qdb_ts_range_t * ranges,
|
|
223
223
|
qdb_exp_batch_push_table_t & batch)
|
|
224
224
|
{
|
|
225
|
-
batch.name =
|
|
225
|
+
batch.name = _table_name.c_str();
|
|
226
226
|
|
|
227
227
|
prepare_table_data(batch.data);
|
|
228
228
|
if (mode == qdb_exp_batch_push_truncate)
|
|
@@ -234,117 +234,94 @@ void staged_table::prepare_batch(qdb_exp_batch_push_mode_t mode,
|
|
|
234
234
|
// Zero-initialize these
|
|
235
235
|
batch.where_duplicate = nullptr;
|
|
236
236
|
batch.where_duplicate_count = 0;
|
|
237
|
-
batch.
|
|
237
|
+
batch.deduplication_mode = qdb_exp_batch_deduplication_mode_disabled;
|
|
238
|
+
batch.creation = qdb_exp_batch_dont_create;
|
|
238
239
|
|
|
239
240
|
enum detail::deduplication_mode_t mode_ = deduplicate_options.mode_;
|
|
240
241
|
|
|
241
|
-
std::visit(
|
|
242
|
+
std::visit(
|
|
243
|
+
[&mode_, &batch](auto const & columns) { _set_deduplication_mode(mode_, columns, batch); },
|
|
242
244
|
deduplicate_options.columns_);
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
namespace qdb
|
|
248
|
-
{
|
|
249
|
-
|
|
250
|
-
void writer::data::append(
|
|
251
|
-
qdb::table const & table, py::handle const & index, py::list const & column_data)
|
|
247
|
+
/* static */ py::kwargs batch_push_mode::ensure(py::kwargs kwargs)
|
|
252
248
|
{
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Additional check that all the data is actually of the same length, and data has been
|
|
257
|
-
* provided for each and every column.
|
|
258
|
-
*/
|
|
259
|
-
if (column_data.size() != table.list_columns().size())
|
|
249
|
+
if (kwargs.contains(kw_push_mode) == false)
|
|
250
|
+
[[unlikely]] // Our pandas/numpy adapters always set this, so unlikely
|
|
260
251
|
{
|
|
261
|
-
throw qdb::invalid_argument_exception{"data must be provided for every table column"};
|
|
262
|
-
}
|
|
263
252
|
|
|
264
|
-
|
|
265
|
-
{
|
|
266
|
-
qdb::masked_array data_ = data.cast<qdb::masked_array>();
|
|
267
|
-
if (data_.size() != static_cast<std::size_t>(index_.size()))
|
|
268
|
-
{
|
|
269
|
-
throw qdb::invalid_argument_exception{
|
|
270
|
-
"every data array should be exactly the same length as the index array"};
|
|
271
|
-
}
|
|
253
|
+
kwargs[batch_push_mode::kw_push_mode] = batch_push_mode::default_push_mode;
|
|
272
254
|
}
|
|
273
255
|
|
|
274
|
-
|
|
256
|
+
return kwargs;
|
|
275
257
|
}
|
|
276
258
|
|
|
277
|
-
|
|
259
|
+
/* static */ py::kwargs batch_push_mode::set(py::kwargs kwargs, qdb_exp_batch_push_mode_t push_mode)
|
|
278
260
|
{
|
|
279
|
-
|
|
280
|
-
|
|
261
|
+
assert(kwargs.contains(kw_push_mode) == false);
|
|
262
|
+
|
|
263
|
+
kwargs[batch_push_mode::kw_push_mode] = push_mode;
|
|
281
264
|
|
|
282
|
-
|
|
265
|
+
return kwargs;
|
|
283
266
|
}
|
|
284
267
|
|
|
285
|
-
|
|
268
|
+
/* static */ qdb_exp_batch_push_mode_t batch_push_mode::from_kwargs(py::kwargs const & kwargs)
|
|
286
269
|
{
|
|
287
|
-
|
|
288
|
-
staged_tables_t staged_tables = _stage_tables(data);
|
|
270
|
+
assert(kwargs.contains(batch_push_mode::kw_push_mode));
|
|
289
271
|
|
|
290
|
-
|
|
272
|
+
return py::cast<qdb_exp_batch_push_mode_t>(kwargs[batch_push_mode::kw_push_mode]);
|
|
291
273
|
}
|
|
292
274
|
|
|
293
|
-
|
|
275
|
+
/* static */ py::kwargs detail::batch_push_flags::ensure(py::kwargs kwargs)
|
|
294
276
|
{
|
|
295
|
-
|
|
296
|
-
|
|
277
|
+
if (kwargs.contains(batch_push_flags::kw_write_through) == false)
|
|
278
|
+
{
|
|
279
|
+
kwargs[batch_push_flags::kw_write_through] = batch_push_flags::default_write_through;
|
|
280
|
+
}
|
|
297
281
|
|
|
298
|
-
|
|
282
|
+
return kwargs;
|
|
299
283
|
}
|
|
300
284
|
|
|
301
|
-
|
|
285
|
+
/* static */ qdb_uint_t detail::batch_push_flags::from_kwargs(py::kwargs const & kwargs)
|
|
302
286
|
{
|
|
303
|
-
|
|
304
|
-
staged_tables_t staged_tables = _stage_tables(data);
|
|
305
|
-
|
|
306
|
-
auto deduplicate = _deduplicate_from_args(args);
|
|
287
|
+
assert(kwargs.contains(batch_push_flags::kw_write_through));
|
|
307
288
|
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
if (!std::holds_alternative<bool>(deduplicate.columns_)
|
|
311
|
-
|| std::get<bool>(deduplicate.columns_) != false) [[unlikely]]
|
|
312
|
-
{
|
|
313
|
-
throw qdb::invalid_argument_exception{"Cannot set `deduplicate` for push_truncate."};
|
|
314
|
-
};
|
|
289
|
+
// By default no flags are set
|
|
290
|
+
qdb_uint_t ret = qdb_exp_batch_push_flag_none;
|
|
315
291
|
|
|
316
|
-
|
|
317
|
-
// doesn't accidentally truncate his whole database without inserting anything.
|
|
318
|
-
if (data.empty()) [[unlikely]]
|
|
292
|
+
try
|
|
319
293
|
{
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
qdb_ts_range_t tr;
|
|
294
|
+
bool write_through = py::cast<bool>(kwargs["write_through"]);
|
|
324
295
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
else
|
|
330
|
-
{
|
|
331
|
-
// TODO(leon): support multiple tables for push truncate
|
|
332
|
-
if (staged_tables.size() != 1) [[unlikely]]
|
|
296
|
+
// Likely as it's the default, if not, this static assert should fail:
|
|
297
|
+
static_assert(batch_push_flags::default_write_through == true);
|
|
298
|
+
if (write_through == true) [[likely]]
|
|
333
299
|
{
|
|
334
|
-
|
|
335
|
-
"Writer push truncate only supports a single "
|
|
336
|
-
"table unless an explicit range is provided: you provided more than one table without"
|
|
337
|
-
" an explicit range."};
|
|
300
|
+
ret |= static_cast<qdb_uint_t>(qdb_exp_batch_push_flag_write_through);
|
|
338
301
|
}
|
|
302
|
+
}
|
|
303
|
+
catch (py::cast_error const & /*e*/)
|
|
304
|
+
{
|
|
305
|
+
std::string error_msg = "Invalid argument provided for `write_through`: expected bool, got: ";
|
|
306
|
+
error_msg += py::str(py::type::of(kwargs["write_through"])).cast<std::string>();
|
|
339
307
|
|
|
340
|
-
|
|
341
|
-
tr = staged_table.time_range();
|
|
308
|
+
throw qdb::invalid_argument_exception{error_msg};
|
|
342
309
|
}
|
|
343
310
|
|
|
344
|
-
|
|
311
|
+
return ret;
|
|
345
312
|
}
|
|
346
313
|
|
|
347
|
-
detail::
|
|
314
|
+
/* static */ qdb_exp_batch_options_t detail::batch_options::from_kwargs(py::kwargs const & kwargs)
|
|
315
|
+
{
|
|
316
|
+
auto kwargs_ = detail::batch_push_mode::ensure(kwargs);
|
|
317
|
+
|
|
318
|
+
return {
|
|
319
|
+
.mode = detail::batch_push_mode::from_kwargs(kwargs_), //
|
|
320
|
+
.push_flags = detail::batch_push_flags::from_kwargs(kwargs_) //
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/* static */ detail::deduplicate_options detail::deduplicate_options::from_kwargs(py::kwargs args)
|
|
348
325
|
{
|
|
349
326
|
if (!args.contains("deduplicate") || !args.contains("deduplication_mode"))
|
|
350
327
|
{
|
|
@@ -390,11 +367,16 @@ detail::deduplicate_options writer::_deduplicate_from_args(py::kwargs args)
|
|
|
390
367
|
throw qdb::invalid_argument_exception{error_msg};
|
|
391
368
|
};
|
|
392
369
|
|
|
393
|
-
/* static */
|
|
370
|
+
/* static */ staged_tables staged_tables::index(detail::writer_data const & data)
|
|
394
371
|
{
|
|
395
|
-
|
|
372
|
+
// XXX(leon): this function could potentially be moved to e.g. a free
|
|
373
|
+
// function as it doesn't really depend upon anything in writer, but
|
|
374
|
+
// then we'll have to globally declare staged_tables_t and it gets a
|
|
375
|
+
// bit messy.
|
|
376
|
+
|
|
377
|
+
detail::staged_tables ret;
|
|
396
378
|
|
|
397
|
-
for (
|
|
379
|
+
for (detail::writer_data::value_type const & table_data : data.xs())
|
|
398
380
|
{
|
|
399
381
|
qdb::table table = table_data.table;
|
|
400
382
|
py::array index = table_data.index;
|
|
@@ -408,7 +390,7 @@ detail::deduplicate_options writer::_deduplicate_from_args(py::kwargs args)
|
|
|
408
390
|
"data must be provided for every column of the table."};
|
|
409
391
|
}
|
|
410
392
|
|
|
411
|
-
detail::staged_table & staged_table =
|
|
393
|
+
detail::staged_table & staged_table = ret.get_or_create(table);
|
|
412
394
|
|
|
413
395
|
staged_table.set_index(index);
|
|
414
396
|
|
|
@@ -453,82 +435,6 @@ detail::deduplicate_options writer::_deduplicate_from_args(py::kwargs args)
|
|
|
453
435
|
}
|
|
454
436
|
}
|
|
455
437
|
|
|
456
|
-
return
|
|
438
|
+
return ret;
|
|
457
439
|
}
|
|
458
|
-
|
|
459
|
-
void writer::_push_impl(writer::staged_tables_t & staged_tables,
|
|
460
|
-
qdb_exp_batch_push_mode_t mode,
|
|
461
|
-
detail::deduplicate_options deduplicate_options,
|
|
462
|
-
qdb_ts_range_t * ranges)
|
|
463
|
-
{
|
|
464
|
-
_handle->check_open();
|
|
465
|
-
|
|
466
|
-
if (staged_tables.empty())
|
|
467
|
-
{
|
|
468
|
-
throw qdb::invalid_argument_exception{"No data written to batch writer."};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
std::vector<qdb_exp_batch_push_table_t> batch;
|
|
472
|
-
batch.assign(staged_tables.size(), qdb_exp_batch_push_table_t());
|
|
473
|
-
|
|
474
|
-
int cur = 0;
|
|
475
|
-
_logger.debug("writer::_push_impl");
|
|
476
|
-
|
|
477
|
-
for (auto pos = staged_tables.begin(); pos != staged_tables.end(); ++pos)
|
|
478
|
-
{
|
|
479
|
-
std::string const & table_name = pos->first;
|
|
480
|
-
detail::staged_table & staged_table = pos->second;
|
|
481
|
-
auto & batch_table = batch.at(cur++);
|
|
482
|
-
|
|
483
|
-
staged_table.prepare_batch(mode, deduplicate_options, ranges, batch_table);
|
|
484
|
-
|
|
485
|
-
if (batch_table.data.column_count == 0) [[unlikely]]
|
|
486
|
-
{
|
|
487
|
-
throw qdb::invalid_argument_exception{
|
|
488
|
-
"Writer is empty: you did not provide any columns to push."};
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
_logger.debug("Pushing %d rows with %d columns in %s", batch_table.data.row_count,
|
|
492
|
-
batch_table.data.column_count, table_name);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// Make sure to measure the time it takes to do the actual push
|
|
496
|
-
qdb::metrics::scoped_capture capture{"qdb_batch_push"};
|
|
497
|
-
|
|
498
|
-
qdb::qdb_throw_if_error(
|
|
499
|
-
*_handle, qdb_exp_batch_push(*_handle, mode, batch.data(), nullptr, batch.size()));
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
void register_writer(py::module_ & m)
|
|
503
|
-
{
|
|
504
|
-
namespace py = pybind11;
|
|
505
|
-
|
|
506
|
-
// Writer data
|
|
507
|
-
auto writer_data_c = py::class_<qdb::writer::data>{m, "WriterData"};
|
|
508
|
-
writer_data_c.def(py::init())
|
|
509
|
-
.def("append", &qdb::writer::data::append, py::arg("table"), py::arg("index"),
|
|
510
|
-
py::arg("column_data"), "Append new data")
|
|
511
|
-
.def("empty", &qdb::writer::data::empty, "Returns true if underlying data is empty");
|
|
512
|
-
|
|
513
|
-
// And the actual pinned writer
|
|
514
|
-
auto writer_c = py::class_<qdb::writer>{m, "Writer"};
|
|
515
|
-
|
|
516
|
-
// basic interface
|
|
517
|
-
writer_c.def(py::init<qdb::handle_ptr>()); //
|
|
518
|
-
|
|
519
|
-
writer_c.def_readwrite("_legacy_state", &qdb::writer::legacy_state_);
|
|
520
|
-
|
|
521
|
-
// push functions
|
|
522
|
-
writer_c
|
|
523
|
-
.def("push", &qdb::writer::push, "Regular batch push") //
|
|
524
|
-
.def("push_async", &qdb::writer::push_async,
|
|
525
|
-
"Asynchronous batch push that buffers data inside the QuasarDB daemon") //
|
|
526
|
-
.def("push_fast", &qdb::writer::push_fast,
|
|
527
|
-
"Fast, in-place batch push that is efficient when doing lots of small, incremental "
|
|
528
|
-
"pushes.") //
|
|
529
|
-
.def("push_truncate", &qdb::writer::push_truncate,
|
|
530
|
-
"Before inserting data, truncates any existing data. This is useful when you want your "
|
|
531
|
-
"insertions to be idempotent, e.g. in "
|
|
532
|
-
"case of a retry.");
|
|
533
|
-
}
|
|
534
|
-
}; // namespace qdb
|
|
440
|
+
}; // namespace qdb::detail
|