CDT Read Builders¶
- class aerospike_sdk.aio.operations.cdt_read.CdtReadBuilder[source]¶
Bases:
Generic[T]Terminal read actions and singular navigation for a CDT path.
The parent (type
T) must exposeadd_operation(op)so the builder can register the produced operation before returning it.Navigation fields (
bin_name,ctx,to_ctx) are optional; when not provided, further navigation is not available (terminal-only).Example:
Read values from a map key within a query:: stream = await ( session.query(key) .bin("settings").on_map_key("theme").get_values() .execute() )
- __init__(parent, op_factory, return_type_cls, *, is_map, bin_name='', ctx=(), to_ctx=None, filterable=True)[source]¶
- on_each_child()[source]¶
Continue from this selection as a path over every child.
- Return type:
CdtPathBuilder[TypeVar(T)]- Returns:
A
CdtPathBuilderone level below the current selection.
Example:
.bin("catalog").on_map_key("book").on_each_child().collect_values()
- on_map_keys_in(keys)[source]¶
Continue as a path over the map entries whose key is in keys.
- Parameters:
- Return type:
CdtPathBuilder[TypeVar(T)]- Returns:
A
CdtPathBuilderover the selected entries.- Raises:
TypeError – If keys is a bare
str,bytesorbytearrayrather than a collection of keys.
Example:
.bin("catalog").on_map_key("prices").on_map_keys_in(["a", "c"]).collect_values()
- and_filter(predicate)[source]¶
Continue as a path that keeps this selection only if it matches predicate.
The server evaluates predicate against the element this step selected: a match continues the path with it, a miss selects nothing.
Example:
over_10 = Exp.gt(Exp.int_loop_var(LoopVarPart.VALUE), Exp.val(10)) stream = await ( session.query(key) .bin("prices").on_map_key("book").and_filter(over_10).collect_values() .execute() )
- Parameters:
predicate (
Any) – AnExpover the element’s loop variable.- Return type:
CdtPathBuilder[TypeVar(T)]- Returns:
A
CdtPathBuilderover the filtered selection.- Raises:
TypeError – If this step is a range or multi-element selection, which has no single element to filter, or a map index or rank step, where the server does not return the filtered value correctly.
See also
CdtPathBuilder.and_filter(): the same filter afteron_map_keys_in()or a step inside a path.
- on_map_key(key, *, create_type=None)[source]¶
Navigate into a map element by key.
- Parameters:
- Return type:
- Returns:
CdtReadBuilderfor reading the targeted element.
- Example::
.bin(“m”).on_map_key(“x”).get_values()
- on_map_index(index)[source]¶
Navigate into a map element by index.
- Parameters:
index (
int) – Map index to target.- Return type:
- Returns:
CdtReadBuilderfor reading the targeted element.
- on_map_rank(rank)[source]¶
Navigate into a map element by rank (0 = lowest value).
- Parameters:
rank (
int) – Rank position (0 = lowest value).- Return type:
- Returns:
CdtReadBuilderfor reading the targeted element.
- on_list_index(index, *, order=None, pad=False)[source]¶
Navigate into a list element by index.
- Parameters:
- Return type:
- Returns:
CdtReadBuilderfor reading the targeted element.
- Example::
.bin(“items”).on_list_index(0).get_values()
- on_list_rank(rank)[source]¶
Navigate into a list element by rank (0 = lowest value).
- Parameters:
rank (
int) – Rank position (0 = lowest value).- Return type:
- Returns:
CdtReadBuilderfor reading the targeted element.
- on_map_value(value)[source]¶
Navigate into map elements matching a value (may match multiple).
- Parameters:
value (
Any) – Value to match.- Return type:
- Returns:
CdtReadInvertableBuilderfor reading the selection; further singular navigation is supported when this builder was produced from a nested path.
- on_map_index_range(index, count=None)[source]¶
Navigate into map elements by index range.
- Return type:
- on_map_key_range(start, end)[source]¶
Navigate into map elements by key range
[start, end).- Return type:
- on_map_value_range(start, end)[source]¶
Navigate into map elements by value range
[start, end).- Return type:
- on_map_key_relative_index_range(key, index, count=None)[source]¶
Navigate into map entries by index range relative to an anchor key.
- Return type:
- on_map_value_relative_rank_range(value, rank, count=None)[source]¶
Navigate into map entries by value rank range relative to an anchor.
- Return type:
- on_map_key_list(keys)[source]¶
Navigate into map elements matching a list of keys.
- Parameters:
- Return type:
- Returns:
CdtReadInvertableBuilderfor reading the matched elements.- Raises:
TypeError – If keys is a bare
str,bytesorbytearrayrather than a collection of keys.
- on_map_value_list(values)[source]¶
Navigate into map elements matching a list of values.
- Parameters:
- Return type:
- Returns:
CdtReadInvertableBuilderfor reading the matched elements.- Raises:
TypeError – If values is a bare
str,bytesorbytearrayrather than a collection of values.
- on_list_index_range(index, count=None)[source]¶
Navigate into list elements by index range.
- Return type:
- on_list_rank_range(rank, count=None)[source]¶
Navigate into list elements by rank range.
- Return type:
- on_list_value_range(start, end)[source]¶
Navigate into list elements by value range
[start, end).- Return type:
- on_list_value_relative_rank_range(value, rank, count=None)[source]¶
Navigate into list elements by value rank range relative to anchor.
- Return type:
- on_list_value_list(values)[source]¶
Navigate into list elements matching a list of values.
- Parameters:
- Return type:
- Returns:
CdtReadInvertableBuilderfor reading the matched elements.- Raises:
TypeError – If values is a bare
str,bytesorbytearrayrather than a collection of values.
- get_values()[source]¶
Return value(s) at the current CDT selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- Example::
.bin(“m”).on_map_key(“x”).get_values()
- get_keys()[source]¶
Return map keys at the current CDT selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_keys_and_values()[source]¶
Return map key-value pairs at the current CDT selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
See also
get_as_map(): The same entries as an unordereddict.get_as_ordered_map(): The same entries as a key-orderedSortedMap.
- get_as_map()[source]¶
Return the selected map entries as an unordered
dict.The server returns the entries as an unordered map rather than as key-value pairs, so the result makes no promise about order; use
get_keys_and_values()to keep the server’s selection order orget_as_ordered_map()for key order.Example:
stream = await ( session.query(players.id("p-1001")) .bin("scores").on_map_key_range("a", "m").get_as_map() .execute() ) early = (await stream.first_or_raise()).record.bins["scores"]
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- Raises:
TypeError – If the selection is on a list rather than a map.
See also
get_keys_and_values(): Entries in selection order, as adict.get_as_ordered_map(): Entries in key order, as aSortedMap.
- get_as_ordered_map()[source]¶
Return the selected map entries as a key-ordered
SortedMap.Unlike
get_keys_and_values(), which keeps the order the server selected the entries in (rank order for a rank range), the result is ordered by key whatever the bin’s own map order. Writing it back to a bin stores that map key-ordered.Example:
stream = await ( session.query(players.id("p-1001")) .bin("scores").on_map_rank_range(-3, 3).get_as_ordered_map() .execute() ) top_three = (await stream.first_or_raise()).record.bins["scores"] # SortedMap({"amy": 870, "raj": 910, "zoe": 955})
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- Raises:
TypeError – If the selection is on a list rather than a map.
See also
get_keys_and_values(): Entries in selection order, as adict.
- count()[source]¶
Return the count of elements at the current CDT selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_indexes()[source]¶
Return indexes of the selected CDT elements.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_reverse_indexes()[source]¶
Return reverse indexes of the selected CDT elements.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_ranks()[source]¶
Return ranks of the selected CDT elements.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_reverse_ranks()[source]¶
Return reverse ranks of the selected CDT elements.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- exists()[source]¶
Check whether the selected CDT element(s) exist.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- map_size()[source]¶
Return the element count of the map at the current CDT path.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- list_size()[source]¶
Return the element count of the list at the current CDT path.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- list_join(separator=None)[source]¶
Concatenate the string items of the list at the current CDT path.
The list must hold only strings; any other element type fails with
PARAMETER_ERROR. An empty list joins to an empty string.
- list_get(index)[source]¶
Read the list element at index at the current CDT path.
- Return type:
TypeVar(T)
- list_get_range(index, count=None)[source]¶
Read a slice of the list starting at index (through end if count is
None).- Return type:
TypeVar(T)
- str_strlen()[source]¶
Return the Unicode codepoint count of the string at this CDT path.
Example:
stream = await ( session.query(key) .bin("tags").on_list_index(1).str_strlen() .execute() )
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
See also
str_byte_length(): UTF-8 byte length instead.
- str_substr(start, end=None)[source]¶
Return the codepoint range
[start, end)of the string at this CDT path.endomitted runs to the end of the string; negativestartcounts from the end. Out-of-bounds indexes clamp.
- str_char_at(index)[source]¶
Return the codepoint at
indexas a one-codepoint string.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_contains(needle)[source]¶
Return
Trueiff the string at this CDT path containsneedle.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_starts_with(prefix)[source]¶
Return
Trueiff the string at this CDT path starts withprefix.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_ends_with(suffix)[source]¶
Return
Trueiff the string at this CDT path ends withsuffix.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_to_integer()[source]¶
Parse the string at this CDT path as
int64.Server returns
OP_NOT_APPLICABLE(subcodeSubCode.OPNOT_STRING_CONVERSION_FAILED) if it is not numeric.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_to_double()[source]¶
Parse the string at this CDT path as
float64.Server returns
OP_NOT_APPLICABLE(subcodeSubCode.OPNOT_STRING_CONVERSION_FAILED) if it is not numeric.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_byte_length()[source]¶
Return the UTF-8 byte count of the string at this CDT path.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_is_numeric(numeric_type=None)[source]¶
Return
Trueiff the string at this CDT path parses as a number.- Parameters:
numeric_type (
Optional[StringNumericType]) – Restrict toINTorFLOAT.None= either.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_is_upper()[source]¶
Return
Trueiff every cased codepoint at this CDT path is uppercase.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_is_lower()[source]¶
Return
Trueiff every cased codepoint at this CDT path is lowercase.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_to_blob()[source]¶
Return the UTF-8 bytes of the string at this CDT path as a blob.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_b64_decode()[source]¶
Base64-decode the string at this CDT path, returning bytes.
Server returns
OP_NOT_APPLICABLE(subcodeSubCode.OPNOT_STRING_B64_INVALID) if it is not valid base64.- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- str_regex_compare(pattern, flags=0)[source]¶
Return
Trueiff the ICU regexpatternmatches the string at this CDT path.Server returns
OP_NOT_APPLICABLE(subcodeSubCode.OPNOT_STRING_REGEX_LIMIT_EXCEEDED) if matching exceeds the server’s regex resource budget.- Parameters:
pattern (
str) – ICU regex pattern.flags (
int|StringRegexFlags) – OR-combinedStringRegexFlagsbitmask.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- class aerospike_sdk.aio.operations.cdt_read.CdtReadInvertableBuilder[source]¶
Bases:
CdtReadBuilder[T]Terminal read actions with inverted (all-others) variants.
Used for range and list selectors where INVERTED makes semantic sense (e.g. “all keys except those in this range”). When constructed with
to_ctxset (e.g. after a singular value selector on a nested path), singular navigation methods continue the CDT path.Example:
Get all map values *except* those in a key range:: .bin("m").on_map_key_range("a", "d").get_all_other_values()
- get_all_other_values()[source]¶
Return all values except those matching the selection (INVERTED).
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_all_other_keys()[source]¶
Return all map keys except those matching the selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_all_other_keys_and_values()[source]¶
Return all map key-value pairs except those matching the selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- count_all_others()[source]¶
Return the count of elements except those matching the selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_all_other_indexes()[source]¶
Return indexes of all elements except those matching the selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.
- get_all_other_reverse_indexes()[source]¶
Return reverse indexes of all elements except those matching the selection.
- Return type:
TypeVar(T)- Returns:
The parent builder for chaining.