Filter Generation¶
Filter generation from AEL expressions.
This module provides functionality to generate optimal secondary index Filters from AEL expressions based on available indexes. It splits expressions to use secondary indexes where possible and filter expressions for the rest.
The implementation uses a tree-based approach: 1. Build an expression tree that tracks filter eligibility 2. Mark nodes under OR as “excluded from filter” (can’t use secondary index) 3. Collect all filterable expressions grouped by cardinality 4. Choose the best by cardinality (or alphabetically if tied) 5. Generate complementary Exp, skipping the part used for Filter
- class aerospike_sdk.ael.filter_gen.IndexTypeEnum[source]¶
Bases:
EnumIndex type for filter generation matching.
INTEGERis the preferred name for an integer-valued index — that is the wording used by the Aerospike server from version 8.1.2 onward and by other Aerospike SDKs.NUMERICis retained as a back-compat alias that maps to the same wire type and is interchangeable withINTEGERinto_aerospike().- NUMERIC = 'NUMERIC'¶
- INTEGER = 'INTEGER'¶
- STRING = 'STRING'¶
- GEO2D_SPHERE = 'GEO2D_SPHERE'¶
- BLOB = 'BLOB'¶
- class aerospike_sdk.ael.filter_gen.Index[source]¶
Bases:
objectRepresents an Aerospike secondary index.
- namespace¶
Namespace of the indexed bin.
- bin¶
Name of the indexed bin.
- index_type¶
Type of the index (NUMERIC, STRING, GEO2D_SPHERE).
- name¶
Optional name of the index.
- bin_values_ratio¶
Cardinality ratio (entries_per_bval). Higher = more selective. Used to choose optimal index when multiple are available.
- collection_index_type¶
Collection index type for list/map indexes.
- ctx¶
Array of CTX representing context of the index.
- set_name¶
Aerospike set this index is defined on, when known.
Nonemeans the index is not bound to a specific set (cross-set / null set). Blank strings are normalized toNone.
- index_type: IndexTypeEnum¶
- __init__(bin, index_type, namespace=None, name=None, bin_values_ratio=None, collection_index_type=None, ctx=None, set_name=None)¶
- class aerospike_sdk.ael.filter_gen.IndexContext[source]¶
Bases:
objectHolds namespace and indexes for filter generation.
- namespace¶
Namespace to match with index namespaces.
- indexes¶
Collection of Index objects for filter generation.
- query_set¶
Aerospike set name for the current query. When set, the filter generator restricts secondary-index selection to indexes whose
Index.set_namematches (or is unset, i.e. a cross-set index). WhenNoneor blank, no set-based filtering applies. Blank strings are normalized toNone.
- classmethod of(namespace, indexes)[source]¶
Create IndexContext with namespace and indexes.
- Return type:
- classmethod with_query_set(namespace, query_set, indexes)[source]¶
Create IndexContext that restricts index selection to
query_set.Indexes whose
Index.set_nameisNone(cross-set) remain eligible regardless ofquery_set.- Return type:
- static index_matches_query_set(index, query_set)[source]¶
Whether
indexis eligible for filter selection underquery_set.Returns
Truewhenquery_setisNone(no filtering), the index has no set name (cross-set), or the index’s set name equalsquery_set. Mirrors the semantics used by reference clients so cross-set indexes remain shared by per-set queries.- Return type:
- __init__(namespace, indexes=<factory>, query_set=None)¶
- class aerospike_sdk.ael.filter_gen.ParseResult[source]¶
Bases:
objectResult of parsing an AEL expression with filter generation.
Contains both a secondary index Filter (if applicable) and a filter Exp (for remaining expression parts that can’t use secondary indexes).
- filter¶
Secondary index Filter. None if no applicable index found.
- exp¶
Filter expression for remaining parts. None if fully covered by filter.
- __init__(filter, exp)¶
- class aerospike_sdk.ael.filter_gen.OperationType[source]¶
Bases:
EnumExpression operation types.
- AND = 'AND'¶
- OR = 'OR'¶
- EQ = 'EQ'¶
- NE = 'NE'¶
- GT = 'GT'¶
- GE = 'GE'¶
- LT = 'LT'¶
- LE = 'LE'¶
- NOT = 'NOT'¶
- class aerospike_sdk.ael.filter_gen.ExpressionNode[source]¶
Bases:
objectA node in the expression tree.
Tracks filter eligibility for secondary index selection.
- op: OperationType¶
- left: ExpressionNode | None = None¶
- right: ExpressionNode | None = None¶
- value_type: IndexTypeEnum | None = None¶
- __init__(op, left=None, right=None, bin_name=None, value=None, value_type=None, bin_explicit_type=None, ctx=None, has_secondary_index_filter=False, is_excl_from_secondary_index_filter=False, ael_fragment=None, arith_op=None, arith_constant=None, bin_on_left=None)¶
- class aerospike_sdk.ael.filter_gen.FilterGenerator[source]¶
Bases:
objectGenerates optimal Filter from an AEL expression based on available indexes.
The generator analyzes the expression tree to find parts that can use secondary indexes, choosing the most selective index based on cardinality. Parts that can’t use secondary indexes remain as filter expressions.
- generate(ael_string, placeholder_values=None, *, hint_index_name=None, hint_bin_name=None)[source]¶
Generate Filter and Exp from an AEL expression string.
- Parameters:
ael_string (
str) – The AEL expression string.placeholder_values (
Any) – Optional placeholder values.hint_index_name (
Optional[str]) – If set, the generated Filter uses a_by_indexvariant keyed to this index name instead of the bin name.hint_bin_name (
Optional[str]) – If set, the generated Filter addresses this bin name instead of the one found in the AEL expression.
- Return type:
- Returns:
ParseResult with Filter and/or Exp.