229{
231
233
234 const long long records =
objects->size();
235 const Py_ssize_t
count = to_fetch ? PySequence_Size(to_fetch) : 0;
236 const unsigned int fetch_start = 2 + with_channel + with_time;
238 int j = 0;
240
241 vector<payload_fetcher_t> payload_fetchers;
242
244 {
245 const IObject&
object =
objects->currentRef();
246
248 {
249
250
252 for (Py_ssize_t i = 0;
i <
count;
i++)
253 {
254 PyObject *py_name = PySequence_GetItem(to_fetch, i);
255 const char *
name = _PyUnicode_AsString(py_name);
256 const string type = (
object.payload()
257 .specification()[name]
258 .storageType()
260
262 as_unicode);
263 auto pff =
pf.target<
PyObject* (*)(
const IObject&)>();
265 return NULL;
266 payload_fetchers.push_back(std::move(pf));
267 Py_DECREF(py_name);
268 }
269
270 if (with_time)
271 {
272 PyObject *py_datetime_module = PyImport_ImportModule(
"datetime");
273 if (!py_datetime_module)
274 throw (std::runtime_error("Could not import python datetime_module"));
275
276 py_datetime_class = PyObject_GetAttrString(py_datetime_module,
277 "datetime");
278
279 Py_DECREF(py_datetime_module);
280 }
281 }
282
284
285
286
289
290 if (with_time)
291 {
292 const ITime&
t =
object.insertionTime();
293 static const char *
const argtypes =
const_cast<char *
>(
"iiiiiil");
294
296 PyObject_CallFunction(py_datetime_class, argtypes,
297 t.year(),
t.month(),
t.day(),
298 t.hour(),
t.minute(),
t.second(),
t.nanosecond() / 1000);
299
300 PyTuple_SetItem(one, 2, py_record_time);
301 }
302
303 if (with_channel)
304 {
305 if (channel_name_mapping)
306 {
307
308
310 PyObject *channelName = PyDict_GetItem(channel_name_mapping,
311 channelId);
312 if (channelName)
313 {
314 Py_INCREF(channelName);
315 Py_DECREF(channelId);
316 PyTuple_SET_ITEM(one, 2+with_time, channelName);
317 } else
318 PyTuple_SET_ITEM(one, 2+with_time, channelId);
319
320 } else
321 PyTuple_SET_ITEM(one, 2+with_time,
323 }
324
325
326 for (Py_ssize_t i = 0;
i <
count;
i++)
327 PyTuple_SET_ITEM(one, fetch_start + i, payload_fetchers[i](object));
328
330 if (!one)
331 {
332
333
334
336 return NULL;
337 }
338
339 PyList_Append(
result, one);
340 Py_DECREF(one);
341
342
343 if (
unlikely(loud && ((++j) % 1000 == 0)))
344 {
345 cout << "Progress: " << j << " / " << records << "\r";
346 cout.flush();
347 }
348
349 if (
unlikely(max_records > 0 && j >= max_records))
350 break;
351 }
352
353 if (loud)
354 cout << "Done fetching " << j << " records.\x1B[K" << endl;
355
356 if (py_datetime_class)
357 {
358 Py_DECREF(py_datetime_class);
359 }
360
362}
PyObject * no_conversion_available(const IObject &)
payload_fetcher_t create_payload_fetcher(const char *name, const string &type_name, bool string_to_unicode=false)
std::function< PyObject *(const IObject &)> payload_fetcher_t
PyObject * apply_function(PyObject *function, PyObject *object)
PyObject * make_iov_key(PyObject *iovkey_wrapper, unsigned long long value)