quasardb 3.14.2.dev3__cp310-cp310-macosx_11_0_arm64.whl → 3.14.2.dev5__cp310-cp310-macosx_11_0_arm64.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/CMakeFiles/CMakeDirectoryInformation.cmake +2 -2
- quasardb/Makefile +20 -20
- quasardb/__init__.py +21 -7
- quasardb/cmake_install.cmake +10 -4
- quasardb/date/CMakeFiles/CMakeDirectoryInformation.cmake +2 -2
- quasardb/date/CMakeFiles/Export/a52b05f964b070ee926bcad51d3288af/dateTargets.cmake +2 -2
- quasardb/date/Makefile +20 -20
- quasardb/date/cmake_install.cmake +10 -4
- quasardb/date/dateConfigVersion.cmake +0 -0
- quasardb/date/dateTargets.cmake +2 -2
- quasardb/extensions/writer.py +59 -61
- quasardb/firehose.py +24 -22
- quasardb/libqdb_api.dylib +0 -0
- quasardb/numpy/__init__.py +181 -120
- quasardb/pandas/__init__.py +145 -95
- quasardb/pool.py +13 -2
- quasardb/pybind11/CMakeFiles/CMakeDirectoryInformation.cmake +2 -2
- quasardb/pybind11/Makefile +20 -20
- quasardb/pybind11/cmake_install.cmake +7 -1
- quasardb/quasardb.cpython-310-darwin.so +0 -0
- quasardb/range-v3/CMakeFiles/CMakeDirectoryInformation.cmake +2 -2
- quasardb/range-v3/CMakeFiles/Export/d94ef200eca10a819b5858b33e808f5b/range-v3-targets.cmake +2 -2
- quasardb/range-v3/CMakeFiles/range.v3.headers.dir/build.make +18 -15
- quasardb/range-v3/Makefile +25 -25
- quasardb/range-v3/cmake_install.cmake +13 -7
- quasardb/range-v3/range-v3-config-version.cmake +0 -0
- quasardb/range-v3/range-v3-config.cmake +2 -2
- quasardb/stats.py +92 -80
- quasardb/table_cache.py +5 -1
- {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/METADATA +13 -8
- quasardb-3.14.2.dev5.dist-info/RECORD +45 -0
- {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/WHEEL +1 -1
- quasardb/CMakeLists.txt +0 -517
- quasardb/batch_column.hpp +0 -80
- quasardb/batch_inserter.hpp +0 -248
- quasardb/blob.hpp +0 -150
- quasardb/cluster.cpp +0 -102
- quasardb/cluster.hpp +0 -593
- quasardb/concepts.hpp +0 -322
- quasardb/continuous.cpp +0 -199
- quasardb/continuous.hpp +0 -109
- quasardb/convert/array.hpp +0 -299
- quasardb/convert/point.hpp +0 -330
- quasardb/convert/range.hpp +0 -282
- quasardb/convert/unicode.hpp +0 -598
- quasardb/convert/util.hpp +0 -22
- quasardb/convert/value.hpp +0 -782
- quasardb/convert.hpp +0 -38
- quasardb/detail/invoke.hpp +0 -0
- quasardb/detail/qdb_resource.hpp +0 -129
- quasardb/detail/retry.cpp +0 -30
- quasardb/detail/retry.hpp +0 -147
- quasardb/detail/sleep.hpp +0 -53
- quasardb/detail/ts_column.hpp +0 -224
- quasardb/detail/writer.cpp +0 -440
- quasardb/detail/writer.hpp +0 -550
- quasardb/direct_blob.hpp +0 -108
- quasardb/direct_handle.hpp +0 -83
- quasardb/direct_integer.hpp +0 -94
- quasardb/dispatch.hpp +0 -157
- quasardb/double.hpp +0 -87
- quasardb/entry.hpp +0 -273
- quasardb/error.hpp +0 -393
- quasardb/handle.cpp +0 -29
- quasardb/handle.hpp +0 -98
- quasardb/integer.hpp +0 -88
- quasardb/logger.cpp +0 -106
- quasardb/logger.hpp +0 -228
- quasardb/masked_array.hpp +0 -658
- quasardb/metrics.cpp +0 -103
- quasardb/metrics.hpp +0 -112
- quasardb/module.cpp +0 -92
- quasardb/module.hpp +0 -24
- quasardb/node.hpp +0 -132
- quasardb/numpy.cpp +0 -6
- quasardb/numpy.hpp +0 -489
- quasardb/object_tracker.hpp +0 -282
- quasardb/options.hpp +0 -273
- quasardb/perf.hpp +0 -336
- quasardb/properties.cpp +0 -41
- quasardb/properties.hpp +0 -85
- quasardb/pytypes.hpp +0 -221
- quasardb/query.cpp +0 -420
- quasardb/query.hpp +0 -92
- quasardb/reader.cpp +0 -282
- quasardb/reader.hpp +0 -256
- quasardb/remove_cvref.hpp +0 -31
- quasardb/string.hpp +0 -160
- quasardb/table.cpp +0 -257
- quasardb/table.hpp +0 -366
- quasardb/tag.hpp +0 -77
- quasardb/timestamp.hpp +0 -97
- quasardb/traits.hpp +0 -642
- quasardb/ts_iterator.hpp +0 -193
- quasardb/utils/blob_deque.hpp +0 -96
- quasardb/utils/ostream.hpp +0 -17
- quasardb/utils/permutation.hpp +0 -50
- quasardb/utils/stable_sort.hpp +0 -25
- quasardb/utils/unzip_view.hpp +0 -89
- quasardb/utils.cpp +0 -28
- quasardb/utils.hpp +0 -174
- quasardb/writer.hpp +0 -354
- quasardb-3.14.2.dev3.dist-info/RECORD +0 -115
- {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/LICENSE.md +0 -0
- {quasardb-3.14.2.dev3.dist-info → quasardb-3.14.2.dev5.dist-info}/top_level.txt +0 -0
quasardb/query.cpp
DELETED
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* Official Python API
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2009-2024, 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
|
-
|
|
32
|
-
#include "query.hpp"
|
|
33
|
-
#include "masked_array.hpp"
|
|
34
|
-
#include "metrics.hpp"
|
|
35
|
-
#include "numpy.hpp"
|
|
36
|
-
#include "traits.hpp"
|
|
37
|
-
#include "utils.hpp"
|
|
38
|
-
#include "convert/value.hpp"
|
|
39
|
-
#include "detail/qdb_resource.hpp"
|
|
40
|
-
#include <pybind11/stl.h>
|
|
41
|
-
#include <iostream>
|
|
42
|
-
#include <set>
|
|
43
|
-
#include <sstream>
|
|
44
|
-
#include <string>
|
|
45
|
-
|
|
46
|
-
namespace py = pybind11;
|
|
47
|
-
|
|
48
|
-
namespace qdb
|
|
49
|
-
{
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Options that define whether or not to return blobs as bytearrays or string. Defaults to
|
|
53
|
-
* strings.
|
|
54
|
-
*/
|
|
55
|
-
typedef enum query_blobs_type_t
|
|
56
|
-
{
|
|
57
|
-
query_blobs_type_none = 0,
|
|
58
|
-
query_blobs_type_all = 1,
|
|
59
|
-
query_blobs_type_columns = 2
|
|
60
|
-
} qdb_blobs_type_t;
|
|
61
|
-
|
|
62
|
-
typedef struct
|
|
63
|
-
{
|
|
64
|
-
query_blobs_type_t type;
|
|
65
|
-
std::vector<std::string> columns;
|
|
66
|
-
} query_blobs_t;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Blobs can be provided in a boolean (blobs=True or blobs=False) or as as specific array
|
|
70
|
-
* (blobs=['packet', 'other_packet']).
|
|
71
|
-
*
|
|
72
|
-
* Takes a python object and an array of column names, and returns a bitmap which denotes
|
|
73
|
-
* whether a column needs to be returned as a blob (True) or as a string (False).
|
|
74
|
-
*/
|
|
75
|
-
static std::vector<bool> coerce_blobs_opt(
|
|
76
|
-
const std::vector<std::string> & column_names, const py::object & opts)
|
|
77
|
-
{
|
|
78
|
-
// First try the most common case, a boolean
|
|
79
|
-
try
|
|
80
|
-
{
|
|
81
|
-
bool all_blobs = py::cast<bool>(opts);
|
|
82
|
-
return std::vector<bool>(column_names.size(), all_blobs);
|
|
83
|
-
}
|
|
84
|
-
catch (const std::runtime_error & /*_*/)
|
|
85
|
-
{
|
|
86
|
-
std::vector<std::string> specific_blobs = py::cast<std::vector<std::string>>(opts);
|
|
87
|
-
std::vector<bool> ret;
|
|
88
|
-
ret.reserve(column_names.size());
|
|
89
|
-
|
|
90
|
-
for (auto const & col : column_names)
|
|
91
|
-
{
|
|
92
|
-
ret.push_back(
|
|
93
|
-
std::find(specific_blobs.begin(), specific_blobs.end(), col) != specific_blobs.end());
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return ret;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static py::handle coerce_point(qdb_point_result_t p, bool parse_blob)
|
|
101
|
-
{
|
|
102
|
-
switch (p.type)
|
|
103
|
-
{
|
|
104
|
-
case qdb_query_result_none:
|
|
105
|
-
return Py_None;
|
|
106
|
-
|
|
107
|
-
case qdb_query_result_double:
|
|
108
|
-
return PyFloat_FromDouble(p.payload.double_.value);
|
|
109
|
-
|
|
110
|
-
case qdb_query_result_blob: {
|
|
111
|
-
return PyBytes_FromStringAndSize(static_cast<char const *>(p.payload.blob.content),
|
|
112
|
-
static_cast<Py_ssize_t>(p.payload.blob.content_length));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
case qdb_query_result_string:
|
|
116
|
-
return PyUnicode_FromStringAndSize(static_cast<char const *>(p.payload.string.content),
|
|
117
|
-
static_cast<Py_ssize_t>(p.payload.string.content_length));
|
|
118
|
-
|
|
119
|
-
case qdb_query_result_int64:
|
|
120
|
-
return PyLong_FromLongLong(p.payload.int64_.value);
|
|
121
|
-
|
|
122
|
-
case qdb_query_result_count:
|
|
123
|
-
return PyLong_FromLongLong(p.payload.count.value);
|
|
124
|
-
|
|
125
|
-
case qdb_query_result_timestamp:
|
|
126
|
-
return qdb::numpy::datetime64(p.payload.timestamp.value);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
throw std::runtime_error("Unable to cast QuasarDB type to Python type");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
static std::vector<std::string> coerce_column_names(const qdb_query_result_t & r)
|
|
133
|
-
{
|
|
134
|
-
std::vector<std::string> xs;
|
|
135
|
-
xs.reserve(r.column_count);
|
|
136
|
-
|
|
137
|
-
for (qdb_size_t i = 0; i < r.column_count; ++i)
|
|
138
|
-
{
|
|
139
|
-
xs.push_back(qdb::to_string(r.column_names[i]));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return xs;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
static dict_query_result_t convert_query_results(const qdb_query_result_t * r,
|
|
146
|
-
const std::vector<std::string> & column_names,
|
|
147
|
-
const std::vector<bool> & parse_blobs)
|
|
148
|
-
{
|
|
149
|
-
qdb::dict_query_result_t ret;
|
|
150
|
-
|
|
151
|
-
for (qdb_size_t i = 0; i < r->row_count; ++i)
|
|
152
|
-
{
|
|
153
|
-
std::map<std::string, py::handle> row;
|
|
154
|
-
|
|
155
|
-
for (qdb_size_t j = 0; j < r->column_count; ++j)
|
|
156
|
-
{
|
|
157
|
-
const auto & column_name = column_names[j];
|
|
158
|
-
auto value = coerce_point(r->rows[i][j], parse_blobs[j]);
|
|
159
|
-
|
|
160
|
-
row[column_name] = value;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
ret.push_back(row);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return ret;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
dict_query_result_t convert_query_results(const qdb_query_result_t * r, const py::object & blobs)
|
|
170
|
-
{
|
|
171
|
-
if (!r) return dict_query_result_t{};
|
|
172
|
-
const std::vector<std::string> column_names = coerce_column_names(*r);
|
|
173
|
-
const std::vector<bool> parse_blobs = coerce_blobs_opt(column_names, blobs);
|
|
174
|
-
return convert_query_results(r, column_names, parse_blobs);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
qdb::masked_array numpy_null_array(qdb_size_t row_count)
|
|
178
|
-
{
|
|
179
|
-
py::array::ShapeContainer shape{row_count};
|
|
180
|
-
auto data = qdb::numpy::array::initialize<std::double_t>(
|
|
181
|
-
shape, std::numeric_limits<std::double_t>::quiet_NaN());
|
|
182
|
-
|
|
183
|
-
return qdb::masked_array::masked_all(data);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
template <qdb_query_result_value_type_t ResultType>
|
|
187
|
-
struct numpy_util
|
|
188
|
-
{
|
|
189
|
-
static constexpr decltype(auto) get_value(qdb_point_result_t const &);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
template <>
|
|
193
|
-
struct numpy_util<qdb_query_result_double>
|
|
194
|
-
{
|
|
195
|
-
|
|
196
|
-
using value_type = std::double_t;
|
|
197
|
-
using dtype = traits::float64_dtype;
|
|
198
|
-
|
|
199
|
-
static constexpr std::double_t get_value(qdb_point_result_t const & row) noexcept
|
|
200
|
-
{
|
|
201
|
-
return row.payload.double_.value;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
template <>
|
|
206
|
-
struct numpy_util<qdb_query_result_int64>
|
|
207
|
-
{
|
|
208
|
-
using value_type = std::int64_t;
|
|
209
|
-
using dtype = traits::int64_dtype;
|
|
210
|
-
|
|
211
|
-
static constexpr std::int64_t get_value(qdb_point_result_t const & row) noexcept
|
|
212
|
-
{
|
|
213
|
-
return row.payload.int64_.value;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
template <>
|
|
218
|
-
struct numpy_util<qdb_query_result_blob>
|
|
219
|
-
{
|
|
220
|
-
using value_type = py::object;
|
|
221
|
-
using dtype = traits::pyobject_dtype;
|
|
222
|
-
|
|
223
|
-
static inline py::object get_value(qdb_point_result_t const & row) noexcept
|
|
224
|
-
{
|
|
225
|
-
return py::bytes{
|
|
226
|
-
static_cast<char const *>(row.payload.blob.content), row.payload.blob.content_length};
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
template <>
|
|
231
|
-
struct numpy_util<qdb_query_result_string>
|
|
232
|
-
{
|
|
233
|
-
using value_type = py::object;
|
|
234
|
-
using dtype = traits::pyobject_dtype;
|
|
235
|
-
|
|
236
|
-
static inline py::object get_value(qdb_point_result_t const & row) noexcept
|
|
237
|
-
{
|
|
238
|
-
return py::str{row.payload.string.content, row.payload.string.content_length};
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
template <>
|
|
243
|
-
struct numpy_util<qdb_query_result_count>
|
|
244
|
-
{
|
|
245
|
-
using value_type = std::int64_t;
|
|
246
|
-
using dtype = traits::int64_dtype;
|
|
247
|
-
|
|
248
|
-
static constexpr std::int64_t get_value(qdb_point_result_t const & row) noexcept
|
|
249
|
-
{
|
|
250
|
-
return row.payload.count.value;
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
template <>
|
|
255
|
-
struct numpy_util<qdb_query_result_timestamp>
|
|
256
|
-
{
|
|
257
|
-
using value_type = std::int64_t;
|
|
258
|
-
using dtype = traits::datetime64_ns_dtype;
|
|
259
|
-
|
|
260
|
-
static constexpr std::int64_t get_value(qdb_point_result_t const & row) noexcept
|
|
261
|
-
{
|
|
262
|
-
return convert::value<qdb_timespec_t, std::int64_t>(row.payload.timestamp.value);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
template <qdb_query_result_value_type_t ResultType>
|
|
267
|
-
struct numpy_converter
|
|
268
|
-
{
|
|
269
|
-
using dtype = typename numpy_util<ResultType>::dtype;
|
|
270
|
-
|
|
271
|
-
static decltype(auto) convert(qdb_size_t column, qdb_point_result_t ** rows, qdb_size_t row_count)
|
|
272
|
-
{
|
|
273
|
-
using value_type = typename numpy_util<ResultType>::value_type;
|
|
274
|
-
py::dtype dtype_ = dtype::dtype();
|
|
275
|
-
|
|
276
|
-
auto fn = numpy_util<ResultType>::get_value;
|
|
277
|
-
|
|
278
|
-
py::array data(dtype_, py::array::ShapeContainer{row_count});
|
|
279
|
-
qdb::mask mask = qdb::mask::of_all<true>(row_count);
|
|
280
|
-
|
|
281
|
-
auto data_f = data.template mutable_unchecked<value_type, 1>();
|
|
282
|
-
|
|
283
|
-
bool * mask_ = mask.mutable_data();
|
|
284
|
-
|
|
285
|
-
for (qdb_size_t i = 0; i < row_count; ++i, ++mask_)
|
|
286
|
-
{
|
|
287
|
-
bool masked = (rows[i][column].type == qdb_query_result_none);
|
|
288
|
-
*mask_ = masked;
|
|
289
|
-
|
|
290
|
-
if (!masked)
|
|
291
|
-
{
|
|
292
|
-
data_f(i) = fn(rows[i][column]);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return qdb::masked_array{data, mask};
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Nothing to convert for columns without type, just return an array filled with null
|
|
302
|
-
* values.
|
|
303
|
-
*/
|
|
304
|
-
template <>
|
|
305
|
-
struct numpy_converter<qdb_query_result_none>
|
|
306
|
-
{
|
|
307
|
-
static qdb::masked_array convert(
|
|
308
|
-
qdb_size_t /* column */, qdb_point_result_t ** /* rows */, qdb_size_t row_count)
|
|
309
|
-
{
|
|
310
|
-
return numpy_null_array(row_count);
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
qdb_query_result_value_type_t probe_column_type(qdb_query_result_t const & r, qdb_size_t column)
|
|
315
|
-
{
|
|
316
|
-
// Probe a column for its value type, by returning the type of the first non-null
|
|
317
|
-
// value.
|
|
318
|
-
for (qdb_size_t row = 0; row < r.row_count; ++row)
|
|
319
|
-
{
|
|
320
|
-
if (r.rows[row][column].type != qdb_query_result_none)
|
|
321
|
-
{
|
|
322
|
-
return r.rows[row][column].type;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// No non-null values were part of the dataset.
|
|
327
|
-
return qdb_query_result_none;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
qdb::masked_array numpy_query_array(qdb_query_result_t const & r, qdb_size_t column)
|
|
331
|
-
{
|
|
332
|
-
|
|
333
|
-
switch (probe_column_type(r, column))
|
|
334
|
-
{
|
|
335
|
-
|
|
336
|
-
#define CASE(t) \
|
|
337
|
-
case t: \
|
|
338
|
-
return numpy_converter<t>::convert(column, r.rows, r.row_count);
|
|
339
|
-
|
|
340
|
-
CASE(qdb_query_result_double);
|
|
341
|
-
CASE(qdb_query_result_int64);
|
|
342
|
-
CASE(qdb_query_result_string);
|
|
343
|
-
CASE(qdb_query_result_blob);
|
|
344
|
-
CASE(qdb_query_result_timestamp);
|
|
345
|
-
CASE(qdb_query_result_count);
|
|
346
|
-
CASE(qdb_query_result_none);
|
|
347
|
-
|
|
348
|
-
default: {
|
|
349
|
-
std::stringstream ss;
|
|
350
|
-
ss << "unrecognized query result column type: " << r.rows[0][column].type;
|
|
351
|
-
throw qdb::incompatible_type_exception(ss.str());
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
numpy_query_column_t numpy_query_column(qdb_query_result_t const & r, qdb_size_t column)
|
|
357
|
-
{
|
|
358
|
-
|
|
359
|
-
qdb::numpy_query_column_t ret;
|
|
360
|
-
ret.first = qdb::to_string(r.column_names[column]);
|
|
361
|
-
ret.second = py::cast(numpy_query_array(r, column));
|
|
362
|
-
return ret;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
numpy_query_result_t numpy_query_results(qdb_query_result_t const & r)
|
|
366
|
-
{
|
|
367
|
-
qdb::numpy_query_result_t ret{};
|
|
368
|
-
ret.reserve(r.column_count);
|
|
369
|
-
|
|
370
|
-
// First initialize the result vector. This means storing the column names,
|
|
371
|
-
// and pre-allocating the column result arrays with data points for each .
|
|
372
|
-
for (qdb_size_t j = 0; j < r.column_count; ++j)
|
|
373
|
-
{
|
|
374
|
-
ret.push_back(numpy_query_column(r, j));
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return ret;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
numpy_query_result_t numpy_query_results(const qdb_query_result_t * r)
|
|
381
|
-
{
|
|
382
|
-
if (!r || r->column_count == 0 || r->row_count == 0)
|
|
383
|
-
{
|
|
384
|
-
return numpy_query_result_t{};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const std::vector<std::string> column_names = coerce_column_names(*r);
|
|
388
|
-
return numpy_query_results(*r);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
dict_query_result_t dict_query(qdb::handle_ptr h, const std::string & q, const py::object & blobs)
|
|
392
|
-
{
|
|
393
|
-
detail::qdb_resource<qdb_query_result_t> r{*h};
|
|
394
|
-
|
|
395
|
-
qdb_error_t err;
|
|
396
|
-
{
|
|
397
|
-
metrics::scoped_capture capture{"qdb_query"};
|
|
398
|
-
err = qdb_query(*h, q.c_str(), &r);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
qdb::qdb_throw_if_query_error(*h, err, r.get());
|
|
402
|
-
|
|
403
|
-
return convert_query_results(r, blobs);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
numpy_query_result_t numpy_query(qdb::handle_ptr h, const std::string & q)
|
|
407
|
-
{
|
|
408
|
-
detail::qdb_resource<qdb_query_result_t> r{*h};
|
|
409
|
-
|
|
410
|
-
qdb_error_t err;
|
|
411
|
-
{
|
|
412
|
-
metrics::scoped_capture capture{"qdb_query"};
|
|
413
|
-
err = qdb_query(*h, q.c_str(), &r);
|
|
414
|
-
}
|
|
415
|
-
qdb::qdb_throw_if_query_error(*h, err, r.get());
|
|
416
|
-
|
|
417
|
-
return numpy_query_results(r);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
} // namespace qdb
|
quasardb/query.hpp
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* Official Python API
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2009-2024, 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 "utils.hpp"
|
|
35
|
-
#include <qdb/query.h>
|
|
36
|
-
#include <pybind11/numpy.h>
|
|
37
|
-
#include <map>
|
|
38
|
-
#include <string>
|
|
39
|
-
#include <unordered_map>
|
|
40
|
-
#include <vector>
|
|
41
|
-
|
|
42
|
-
namespace py = pybind11;
|
|
43
|
-
|
|
44
|
-
namespace qdb
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
class find_query
|
|
48
|
-
{
|
|
49
|
-
public:
|
|
50
|
-
find_query(qdb::handle_ptr h, const std::string & query_string)
|
|
51
|
-
: _handle{h}
|
|
52
|
-
, _query_string{query_string}
|
|
53
|
-
{}
|
|
54
|
-
|
|
55
|
-
public:
|
|
56
|
-
std::vector<std::string> run()
|
|
57
|
-
{
|
|
58
|
-
const char ** aliases = nullptr;
|
|
59
|
-
size_t count = 0;
|
|
60
|
-
|
|
61
|
-
qdb::qdb_throw_if_error(
|
|
62
|
-
*_handle, qdb_query_find(*_handle, _query_string.c_str(), &aliases, &count));
|
|
63
|
-
|
|
64
|
-
return convert_strings_and_release(_handle, aliases, count);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private:
|
|
68
|
-
qdb::handle_ptr _handle;
|
|
69
|
-
std::string _query_string;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
using dict_query_result_t = std::vector<std::map<std::string, py::handle>>;
|
|
73
|
-
using numpy_query_column_t = std::pair<std::string, py::object>;
|
|
74
|
-
using numpy_query_result_t = std::vector<numpy_query_column_t>;
|
|
75
|
-
|
|
76
|
-
dict_query_result_t convert_query_results(const qdb_query_result_t * r, const py::object & blobs);
|
|
77
|
-
dict_query_result_t dict_query(qdb::handle_ptr h, const std::string & query, const py::object & blobs);
|
|
78
|
-
numpy_query_result_t numpy_query(qdb::handle_ptr h, const std::string & query);
|
|
79
|
-
|
|
80
|
-
template <typename Module>
|
|
81
|
-
static inline void register_query(Module & m)
|
|
82
|
-
{
|
|
83
|
-
namespace py = pybind11;
|
|
84
|
-
|
|
85
|
-
py::class_<qdb::find_query>{m, "FindQuery"} //
|
|
86
|
-
.def(py::init<qdb::handle_ptr, const std::string &>()) //
|
|
87
|
-
.def("run", &qdb::find_query::run); //
|
|
88
|
-
|
|
89
|
-
m.def("dict_query", &qdb::dict_query);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
} // namespace qdb
|