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.
- NUMERIC = 'NUMERIC'¶
- 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.
- index_type: IndexTypeEnum¶
- __init__(bin, index_type, namespace=None, name=None, bin_values_ratio=None, collection_index_type=None, ctx=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.
- classmethod of(namespace, indexes)[source]¶
Create IndexContext with namespace and indexes.
- Return type:
- __init__(namespace, indexes=<factory>)¶
- 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.