RecordResult

class aerospike_sdk.record_result.RecordResult[source]

Bases: object

One row from a batch, query stream, or single-key SDK call.

Inspect is_ok and result_code for outcome; use or_raise() or record_or_raise() when failures should throw. Foreground UDF success values appear in udf_result when returned by the server.

key

Target Key for this row.

record

Record payload, or None if not returned (errors, not found, or UDF error rows).

result_code

The row’s ResultCode: the server’s code, or a client code (such as CLIENT_ERROR) for a row that failed before the server answered.

in_doubt

True when a write may have completed despite an error.

index

Batch position, or 0 / -1 depending on origin.

exception

Embedded AerospikeError when the client placed an error in-stream instead of raising.

udf_result

Lua return value for successful foreground UDF calls.

sub_code

Server error subcode for this row, or None. Populated only for failed batch rows when the request asked for extended error detail (error_detail_verbosity) and the server supplies it (8.2.0+). Subcode values are scoped to their parent result_code — interpret the pair together.

server_message

The server’s human-readable explanation for this row’s failure, or None. Populated on the same terms as sub_code (and requires message-level verbosity).

exp_trace

Server-supplied expression build trace for this row, or None when absent — only attached on expression build failures at the highest verbosity. Populated on the same terms as sub_code.

Example:

Inspect a row from a stream::

    row = await stream.first()
    if row and row.is_ok:
        bins = row.record.bins if row.record else {}
    elif row:
        row.or_raise()

See also

RecordStream: Async iteration of results.

key: Key
record: Record | None
result_code: ResultCode
in_doubt: bool
index: int
exception: AerospikeError | None
udf_result: Any | None
sub_code: int | None
server_message: str | None
exp_trace: ExpressionTrace | None
__init__(key, record, result_code, in_doubt=False, index=-1, exception=None, udf_result=None, sub_code=None, server_message=None, exp_trace=None)[source]
property is_ok: bool

Whether this row succeeded.

True only when result_code is ResultCode.OK and no exception is attached.

Returns:

True on success; False for any other result code, and for any row carrying an exception.

Example:

row = await stream.first()
if row is not None and row.is_ok and row.record:
    bins = row.record.bins
or_raise()[source]

Return self if successful, else raise from exception or result code.

Return type:

RecordResult

Returns:

This instance when is_ok is true.

Raises:

AerospikeError – The exception to_exception() returns for this row.

Example:

row = await stream.first()
if row is not None:
    row.or_raise()

See also

to_exception(): The same exception, returned instead of raised.

to_exception()[source]

Return this row’s failure as an exception, or None if the row succeeded.

A row the client failed carries its own exception, which is returned as is. Otherwise the exception is built from the row: the AerospikeError subclass for result_code (the base type for an unmapped code), with in_doubt, sub_code, server_message and exp_trace attached. Use it to log or collect failures without raising.

Return type:

AerospikeError | None

Returns:

The exception for a failed row, or None when is_ok is true.

Example:

from aerospike_sdk.exceptions import RecordNotFoundError

async for row in stream:
    exc = row.to_exception()
    if isinstance(exc, RecordNotFoundError):
        missing.append(row.key)
    elif exc is not None:
        failures.append(exc)

See also

or_raise(): Raise this exception instead of returning it.

record_or_raise()[source]

Return record, raising if the result is not OK.

Return type:

Record

Returns:

The non-None Record.

:raises Same as or_raise`(), plus ``ValueError` if the result is OK: :raises but record is None (unexpected empty payload).:

Example:

rec = (await stream.first_or_raise()).record_or_raise()
operation_result(i)[source]

Return the positional result for the i-th op in the originating request.

Slots are filled in op-arrival order. Ops that produced no value (e.g. write-only modifies that don’t return) carry Python None; an out-of-range i also returns None. If record is None (error rows), this also returns None.

Use this when a single execute issues multiple ops and you need to address each result by its op index. For by-name access, prefer self.record.bins.

Parameters:

i (int) – Zero-based op index into the originating request.

Return type:

Any

Returns:

The Python value at that op position, or None.

Example:

result = await (
    session.upsert(key).bin("s").str_upper().bin("s").get().execute()
).first_or_raise()
assert result.operation_result(1) == "AB"
typed_operation_result(i)[source]

Return the i-th positional result wrapped in an OperationResult.

Same slot semantics as operation_result() — one slot per op in request order — but the value comes back inside the typed-accessor wrapper, so mismatched reads raise TypeError instead of propagating a miscast value. Ops that produced no value (write-only modifies) wrap None; an out-of-range i or an error row (record is None) returns None — no wrapper — mirroring the raw accessor.

Use the raw operation_result() when you just want the value; use this when you want per-op type enforcement.

Parameters:

i (int) – Zero-based op index into the originating request.

Return type:

OperationResult | None

Returns:

An OperationResult wrapping the slot’s value, or None for out-of-range indices and error rows.

Example:

result = await (
    session.upsert(key).bin("s").str_upper().bin("s").get().execute()
).first_or_raise()
assert result.typed_operation_result(1).get_string() == "AB"

See also

operation_result(): The raw, zero-allocation accessor.

get_hll_config(bin_name)[source]

Return the HLL bin’s HllConfig from a hll_describe() result.

Wraps the two-element [index_bit_count, min_hash_bit_count] list that hll_describe() writes back into the bin and returns it as an HllConfig. When the bin carried several ops in the same execute(), such as hll_init() followed by hll_describe(), the bin holds one slot per op and the describe result is the last one that is not None; that slot is used. Returns None if the bin is absent from the record (or the record itself is None).

Parameters:

bin_name (str) – Name of the bin holding a hll_describe() result.

Return type:

HllConfig | None

Returns:

An HllConfig, or None if the bin is absent.

Raises:

TypeError – If the bin value is not a 2-element list of ints.

Example:

result = await (
    session.update(key).bin("h").hll_describe().execute()
).first_or_raise()
cfg = result.get_hll_config("h")
assert cfg.index_bit_count == 14
as_bool()[source]

Interpret the row as an existence check (for example after Session.exists()).

Return type:

bool

Returns:

True if the key exists (OK result). False if the result is key-not-found.

Raises:

AerospikeError – For any other non-OK code (via or_raise()).

Example:

found = (await exists_stream.first_or_raise()).as_bool()