tyneq / QueryPlanWalker
Class: QueryPlanWalker
Defined in: src/queryplan/QueryPlanWalker.ts:54
Concrete base class for side-effect query plan visitors.
Remarks
Traverses the node chain calling QueryPlanWalker.visitNode once per node. The traversal direction defaults to "source-to-terminal" (bottom-up: from before where before select) and can be changed to "terminal-to-source" (top-down) via the options object.
Usage patterns
Direct instantiation with a callback - no subclass needed for simple traversals:
const names: string[] = [];
new QueryPlanWalker({ callback: node => names.push(node.operatorName) }).visit(plan);Subclass - for stateful walkers that accumulate results across nodes:
class NodeCounter extends QueryPlanWalker {
public count = 0;
protected override visitNode(_node: QueryPlanNode): void { this.count++; }
}
const counter = new NodeCounter();
counter.visit(seq[tyneqQueryNode]!);
console.log(counter.count); // number of operators in the pipelineTop-down traversal:
new QueryPlanWalker({
callback: node => console.log(node.operatorName),
direction: "terminal-to-source",
}).visit(plan);Subclass with direction override - pass options to super:
class ReverseCollector extends QueryPlanWalker {
public readonly names: string[] = [];
public constructor() { super({ direction: "terminal-to-source" }); }
protected override visitNode(node: QueryPlanNode): void {
this.names.push(node.operatorName);
}
}Implements
QueryPlanVisitor<void>
Constructors
Constructor
new QueryPlanWalker(
options?):QueryPlanWalker
Defined in: src/queryplan/QueryPlanWalker.ts:62
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | QueryPlanWalkerOptions | Optional configuration for the walker. |
Returns
QueryPlanWalker
Methods
visit()
visit(
node):void
Defined in: src/queryplan/QueryPlanWalker.ts:71
Walks the full chain rooted at node, calling visitNode for each node in the configured direction.
Parameters
| Parameter | Type |
|---|---|
node | IQueryNode |
Returns
void
Implementation of
visitNode()
protectedvisitNode(node):void
Defined in: src/queryplan/QueryPlanWalker.ts:98
Called once per node during traversal.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | IQueryNode | The current node being visited. |
Returns
void
Remarks
The default implementation fires the callback passed via options (if any). Override this method in a subclass to provide custom behaviour. Subclasses that override this method decide whether to call super.visitNode(node) to also fire the options callback.