Skip to content

Commit

Permalink
[CLIENT-1978] Add client.batch_read() (#463)
Browse files Browse the repository at this point in the history
* Deprecate get_many(), select_many(), and exists_many()
* [CLIENT-1838] Lock pysemver version to unblock build wheels workflow
  • Loading branch information
juliannguyen4 authored Jul 17, 2023
1 parent 04ed9eb commit 3747ddb
Show file tree
Hide file tree
Showing 16 changed files with 515 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Get new version and build number
run: |
pip install python-semantic-release
pip install python-semantic-release==7.*
latest_tag=$(cat VERSION)
echo "Bumping off of latest tag $latest_tag"
new_tag=$(pysemver bump prerelease $latest_tag)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.0.0-rc.5
12.0.0-rc.11
1 change: 1 addition & 0 deletions aerospike-stubs/aerospike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class Client:
def batch_get_ops(self, keys: list, ops: list, policy: dict) -> list: ...
def batch_operate(self, keys: list, ops: list, policy_batch: dict = ..., policy_batch_write: dict = ...) -> BatchRecords: ...
def batch_remove(self, keys: list, policy_batch: dict = ..., policy_batch_remove: dict = ...) -> BatchRecords: ...
def batch_read(self, keys: list, bins: list[str] = ..., policy_batch: dict = ...) -> BatchRecords: ...
def batch_write(self, batch_records: BatchRecords, policy_batch: dict = ...) -> BatchRecords: ...
def close(self) -> None: ...
def connect(self, username: str = ..., password: str = ...) -> Client: ...
Expand Down
30 changes: 30 additions & 0 deletions doc/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ Batch Operations
.. include:: examples/get_many.py
:code: python

.. deprecated:: 12.0.0
Use :meth:`batch_read` instead.

.. method:: exists_many(keys[, policy: dict]) -> [ (key, meta)]

Batch-read metadata for multiple keys.
Expand All @@ -255,6 +258,9 @@ Batch Operations
.. include:: examples/exists_many.py
:code: python

.. deprecated:: 12.0.0
Use :meth:`batch_read` instead.

.. method:: select_many(keys, bins: list[, policy: dict]) -> [(key, meta, bins), ...]}

Batch-read specific bins from multiple records.
Expand All @@ -270,6 +276,9 @@ Batch Operations
.. include:: examples/select_many.py
:code: python

.. deprecated:: 12.0.0
Use :meth:`batch_read` instead.

.. method:: batch_get_ops(keys, ops, policy: dict) -> [ (key, meta, bins)]

Batch-read multiple records, and return them as a :class:`list`.
Expand Down Expand Up @@ -328,6 +337,27 @@ Batch Operations
.. seealso:: More information about the \
batch helpers :ref:`aerospike_operation_helpers.batch`

.. method:: batch_read(keys: list, [bins: list], [policy_batch: dict]) -> BatchRecords

Read multiple records.

If a list of bin names is not provided, return all the bins for each record.

If a list of bin names is provided, return only these bins for the given list of records.

If an empty list of bin names is provided, only the metadata of each record will be returned.
Each ``BatchRecord.record`` in ``BatchRecords.batch_records`` will only be a 2-tuple ``(key, meta)``.

:param list keys: The key tuples of the records to fetch.
:param list[str] bins: List of bin names to fetch for each record.
:param dict policy_batch: See :ref:`aerospike_batch_policies`.

:return: an instance of :class:`BatchRecords <aerospike_helpers.batch.records>`.

:raises: A subclass of :exc:`~aerospike.exception.AerospikeError`.

.. note:: Requires server version >= 6.0.0.

.. method:: batch_operate(keys: list, ops: list, [policy_batch: dict], [policy_batch_write: dict]) -> BatchRecords

Perform the same read/write transactions on multiple keys.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def clean():
'src/main/client/batch_write.c',
'src/main/client/batch_operate.c',
'src/main/client/batch_remove.c',
'src/main/client/batch_apply.c'
'src/main/client/batch_apply.c',
'src/main/client/batch_read.c'
],

# Compile
Expand Down
9 changes: 9 additions & 0 deletions src/include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ PyObject *AerospikeClient_BatchWrite(AerospikeClient *self, PyObject *args,
PyObject *AerospikeClient_Batch_Operate(AerospikeClient *self, PyObject *args,
PyObject *kwds);

/**
* Perform reads on multiple keys.
*
* client.batch_read([keys], [bins], policy_batch)
*
*/
PyObject *AerospikeClient_BatchRead(AerospikeClient *self, PyObject *args,
PyObject *kwds);

/**
* Remove multiple records by key.
* Requires server version 6.0+
Expand Down
3 changes: 2 additions & 1 deletion src/include/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,5 @@ as_status as_partition_status_to_pyobject(

as_status as_batch_result_to_BatchRecord(AerospikeClient *self, as_error *err,
as_batch_result *bres,
PyObject *py_batch_record);
PyObject *py_batch_record,
bool checking_if_records_exist);
2 changes: 1 addition & 1 deletion src/main/aerospike.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int Aerospike_Clear(PyObject *aerospike)
PyMODINIT_FUNC PyInit_aerospike(void)
{

const char version[] = "12.0.0-rc.5";
const char version[] = "12.0.0-rc.11";
// Makes things "thread-safe"
Py_Initialize();
int i = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/main/client/batch_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ static bool batch_apply_cb(const as_batch_result *results, uint32_t n,
}
Py_DECREF(py_key);

as_batch_result_to_BatchRecord(data->client, &err, res,
py_batch_record);
as_batch_result_to_BatchRecord(data->client, &err, res, py_batch_record,
false);
if (err.code != AEROSPIKE_OK) {
as_log_error(
"as_batch_result_to_BatchRecord failed at results index: %d",
Expand Down
4 changes: 2 additions & 2 deletions src/main/client/batch_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ static bool batch_operate_cb(const as_batch_result *results, uint32_t n,
}
Py_DECREF(py_key);

as_batch_result_to_BatchRecord(data->client, &err, res,
py_batch_record);
as_batch_result_to_BatchRecord(data->client, &err, res, py_batch_record,
false);
if (err.code != AEROSPIKE_OK) {
as_log_error(
"as_batch_result_to_BatchRecord failed at results index: %d",
Expand Down
Loading

0 comments on commit 3747ddb

Please sign in to comment.