Batch Operation Builders¶
BatchOperationBuilder - Builder for chaining operations across multiple keys.
- class aerospike_sdk.aio.operations.batch.BatchBinBuilder[source]¶
Bases:
objectBuilder for chaining bin operations within a batch key operation.
Example
batch.insert(key).bin(“name”).set_to(“Alice”).bin(“age”).set_to(25)
- set_to(value)[source]¶
Set a bin value.
- Parameters:
value (
Any) – The value to set.- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- set_to_geo_json(geo_json)[source]¶
Set the bin to a GeoJSON value from its string form.
The bin’s server-side particle type is GEOJSON, not STRING. Equivalent to
set_to(GeoJSON(geo_json))but reads naturally for spatial data.- Parameters:
geo_json (
str) – A GeoJSON string (e.g. a Point, Polygon, or AeroCircle).- Return type:
- Returns:
The parent
BatchKeyOperationBuilder.
- append(value)[source]¶
Append a string to a bin value.
- Parameters:
value (
str) – The string to append.- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- prepend(value)[source]¶
Prepend a string to a bin value.
- Parameters:
value (
str) – The string to prepend.- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- select_from(expression, *, ignore_eval_failure=False)[source]¶
Read the result of an expression into this bin.
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- insert_from(expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result to this bin only if it does not already exist.
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- update_from(expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result to this bin only if it already exists.
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- upsert_from(expression, *, ignore_op_failure=False, ignore_eval_failure=False, delete_if_null=False)[source]¶
Write expression result to this bin (create or update).
- Parameters:
- Return type:
- Returns:
The parent BatchKeyOperationBuilder for chaining.
- hll_init(config, *, create_only=False, update_only=False, no_fail=False, allow_fold=False)[source]¶
Initialize an empty HyperLogLog sketch in this bin.
Semantics match
aerospike_sdk.aio.operations.query.WriteBinBuilder.hll_init().- Return type:
- hll_add(values, *, config=None, create_only=False, update_only=False, no_fail=False, allow_fold=False)[source]¶
Add distinct values to the HyperLogLog sketch in this bin.
Semantics match
aerospike_sdk.aio.operations.query.WriteBinBuilder.hll_add().- Return type:
- hll_set_union(hll_list, *, create_only=False, update_only=False, no_fail=False, allow_fold=False)[source]¶
Merge other HyperLogLog sketches into this bin (destructive union).
- Return type:
- hll_get_union(hll_list)[source]¶
Read the union of this sketch with other sketches (non-destructive).
- Return type:
- hll_get_union_count(hll_list)[source]¶
Read the estimated cardinality of the union with other sketches.
- Return type:
- hll_get_intersect_count(hll_list)[source]¶
Read the estimated intersection cardinality with other sketches.
- Return type:
- class aerospike_sdk.aio.operations.batch.BatchKeyOperationBuilder[source]¶
Bases:
_BatchKeyOperationBuilderBaseBuilder for a single key’s operation within a batch.
This class allows chaining bin operations and then continuing to add more keys to the batch.
Example
- batch.insert(key1).bin(“name”).set_to(“Alice”)
.update(key2).bin(“counter”).add(1)
- async execute(on_error=None)[source]¶
Execute all batch operations.
- Parameters:
on_error (
Optional[Callable[[Key,int,AerospikeError],None]]) – Optional(key, index, exception) -> Nonecallback. Failed per-key results are dispatched to the handler and excluded from the returned stream.- Return type:
- async execute_stream(on_error=None)[source]¶
Lazy streaming batch execute. See
BatchOperationBuilder.execute_stream().- Return type:
- class aerospike_sdk.aio.operations.batch.BatchOperationBuilder[source]¶
Bases:
_BatchOperationBuilderBaseBuilder for chaining operations across multiple keys.
This class enables method chaining of operations on different keys, which are then executed as a single batch operation.
Example:
results = await session.batch() \ .insert(key1).bin("name").set_to("Alice").bin("age").set_to(25) \ .update(key2).bin("counter").add(1) \ .delete(key3) \ .execute()
The operations are collected and executed together using the async client’s batch_operate method for optimal performance.
- async execute(on_error=None)[source]¶
Execute all batch operations as a buffered call.
Awaits all per-key results before returning a
RecordStreambacked by a fully-materialized list. Writes are guaranteed to have completed server-side by the time this method returns; subsequent reads will observe the new state without races. Callers that don’t iterate the returned stream are safe — the “fire-and-forget” shape works as expected.For true per-record streaming (records arrive at first-RTT, peak memory bounded), see
execute_stream()— note its different semantics (completion-order yields, no writes-complete-on-return guarantee, peak memory bounded).Internally dispatches as a single mixed PAC
batchcall over pre-wrappedBatchWriteOp/BatchReadOp/BatchDeleteOpentries — each per-key write carries its ownBatchWritePolicyso the verb’s existence semantics (updaterequires existing,insertrequires absent, …) are enforced on the wire. Results land in input order.Example:
stream = await ( session.batch() .insert(key1) .bin("name").set_to("Ada") .upsert(key2) .bin("n").set_to(1) .execute() ) rows = await stream.collect()
- Parameters:
on_error (
Optional[Callable[[Key,int,AerospikeError],None]]) – Optional(key, index, exception) -> Nonecallback. When set, failed per-key results are dispatched to the callback and excluded from the returned stream — the stream contains only successes. Cluster-level errors still raise.- Return type:
- Returns:
A
RecordStreamof per-keyRecordResultitems, backed by a materialized list (positional viaRecordResult.index).- Raises:
ValueError – If no operations have been added.
- async execute_stream(on_error=None)[source]¶
Lazy streaming batch execute — yields records in completion order.
Builds a single mixed PAC
batch_streamcall covering all ops (reads, writes, deletes) and returns aRecordStreamwhose__anext__pulls(idx, BatchRecord)tuples from the PAC stream one at a time. First record arrives at first-RTT, not after all keys complete; peak memory is bounded.Caveats — differ from
execute():Yields completion order, not input order. Each
RecordResultcarries its originating op’s input position inRecordResult.index; sort after collecting if positional results are needed.Per-key errors inline on
RecordResult(whenon_erroris unset); cluster-level errors raise from__anext__.No writes-complete-on-return guarantee. Per-node tasks dispatch in the background; if the caller awaits this method but never iterates the returned stream, server-side writes may still be in-flight when subsequent code runs. Callers that need writes-complete-on-return — or use the “fire-and-forget” shape (
await session.batch()...execute_stream()without draining) — must useexecute()instead.
Per-key op composition is inspected via
aerospike_async.has_any_write_op()to choose the right PAC op wrapper: read-only op lists (e.g. AELselect_fromexpressions) land asBatchReadOp, write/mutation op lists asBatchWriteOp. Matches the wire-dispatch behavior of the bufferedexecute()path.- Parameters:
on_error (
Optional[Callable[[Key,int,AerospikeError],None]]) – Optional(key, index, exception) -> Nonecallback. When set, per-key failures are dispatched to the handler as records arrive and excluded from the returned stream; cluster-level errors still raise from__anext__.- Return type:
- Returns:
A lazy
RecordStream.async forit to drive PAC’s per-record yield.- Raises:
ValueError – If no operations have been added.