RecordResult¶
- class aerospike_sdk.record_result.RecordResult[source]¶
Bases:
objectOne row from a batch, query stream, or single-key SDK call.
Inspect
is_okandresult_codefor outcome; useor_raise()orrecord_or_raise()when failures should throw. Foreground UDF success values appear inudf_resultwhen returned by the server.- key¶
Target
Keyfor this row.
- record¶
Recordpayload, orNoneif not returned (errors, not found, or UDF error rows).
- result_code¶
The row’s
ResultCode: the server’s code, or a client code (such asCLIENT_ERROR) for a row that failed before the server answered.
- in_doubt¶
Truewhen a write may have completed despite an error.
- index¶
Batch position, or
0/-1depending on origin.
- exception¶
Embedded
AerospikeErrorwhen 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 parentresult_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 assub_code(and requires message-level verbosity).
- exp_trace¶
Server-supplied expression build trace for this row, or
Nonewhen absent — only attached on expression build failures at the highest verbosity. Populated on the same terms assub_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¶
- result_code: ResultCode¶
- exception: AerospikeError | 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.
Trueonly whenresult_codeisResultCode.OKand noexceptionis attached.- Returns:
Trueon success;Falsefor any other result code, and for any row carrying anexception.
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
selfif successful, else raise fromexceptionor result code.- Return type:
- Returns:
This instance when
is_okis 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
Noneif 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: theAerospikeErrorsubclass forresult_code(the base type for an unmapped code), within_doubt,sub_code,server_messageandexp_traceattached. Use it to log or collect failures without raising.- Return type:
- Returns:
The exception for a failed row, or
Nonewhenis_okis 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-
NoneRecord.
:raises Same as
or_raise`(),plus ``ValueError`if the result is OK: :raises butrecordisNone(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 returnsNone. IfrecordisNone(error rows), this also returnsNone.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:
- 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 raiseTypeErrorinstead of propagating a miscast value. Ops that produced no value (write-only modifies) wrapNone; an out-of-range i or an error row (recordisNone) returnsNone— 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:
- Returns:
An
OperationResultwrapping the slot’s value, orNonefor 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
HllConfigfrom ahll_describe()result.Wraps the two-element
[index_bit_count, min_hash_bit_count]list thathll_describe()writes back into the bin and returns it as anHllConfig. When the bin carried several ops in the sameexecute(), such ashll_init()followed byhll_describe(), the bin holds one slot per op and the describe result is the last one that is notNone; that slot is used. ReturnsNoneif the bin is absent from the record (or the record itself isNone).- Parameters:
bin_name (
str) – Name of the bin holding ahll_describe()result.- Return type:
- Returns:
An
HllConfig, orNoneif 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:
- Returns:
Trueif the key exists (OK result).Falseif 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()