neosqlite.collection.expr_evaluator.context module¶
Context management and helper functions for expression evaluation.
This module provides the AggregationContext class for managing variable scoping and helper functions for identifying different types of expression values.
Note: Type checking helpers (_is_expression, _is_field_reference, _is_literal) have been moved to collection.type_utils for shared use across subpackages. They are re-exported here for backward compatibility.
- class neosqlite.collection.expr_evaluator.context.AggregationContext[source]¶
Bases:
objectManages variable scoping for aggregation expressions.
Aggregation expressions have different variable contexts than query expressions. This class manages the lifecycle of aggregation variables like $$ROOT, $$CURRENT, and $$REMOVE throughout pipeline execution.
- variables¶
Dictionary mapping variable names to their values
- stage_index¶
Current stage index in the pipeline
- current_field¶
Name of the field being computed (for context)
- pipeline_id¶
Unique identifier for the pipeline (for temp table correlation)
- bind_document(doc: dict[str, Any]) None[source]¶
Bind document to context.
Called at the start of pipeline execution to initialize $$ROOT and $$CURRENT with the input document.
- Parameters:
doc – The document to bind
- update_current(doc: dict[str, Any]) None[source]¶
Update current document after stage processing.
Called after each stage that modifies the document to update the $$CURRENT variable.
- Parameters:
doc – The updated document
- get_variable(name: str) Any[source]¶
Get variable value.
- Parameters:
name – Variable name (e.g., “$$ROOT”, “$$CURRENT”)
- Returns:
Variable value or None if not found
- set_variable(name: str, value: Any) None[source]¶
Set variable value.
- Parameters:
name – Variable name
value – Value to set
- clone() AggregationContext[source]¶
Create a shallow copy of the context for nested scoping.
- Returns:
A copy of the context.
- Return type:
- neosqlite.collection.expr_evaluator.context._is_aggregation_variable(value: Any) bool[source]¶
Check for aggregation variables.
Aggregation variables start with ‘$$’ (e.g., $$ROOT, $$CURRENT).
- Parameters:
value – Value to check
- Returns:
True if value is an aggregation variable, False otherwise
Examples
>>> _is_aggregation_variable("$$ROOT") True >>> _is_aggregation_variable("$$CURRENT") True >>> _is_aggregation_variable("$field") False