Skip to content

tyneq


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:

ts
const names: string[] = [];
new QueryPlanWalker({ callback: node => names.push(node.operatorName) }).visit(plan);

Subclass - for stateful walkers that accumulate results across nodes:

ts
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 pipeline

Top-down traversal:

ts
new QueryPlanWalker({
    callback: node => console.log(node.operatorName),
    direction: "terminal-to-source",
}).visit(plan);

Subclass with direction override - pass options to super:

ts
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

Constructors

Constructor

new QueryPlanWalker(options?): QueryPlanWalker

Defined in: src/queryplan/QueryPlanWalker.ts:62

Parameters

ParameterTypeDescription
options?QueryPlanWalkerOptionsOptional 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

ParameterType
nodeIQueryNode

Returns

void

Implementation of

QueryPlanVisitor.visit


visitNode()

protected visitNode(node): void

Defined in: src/queryplan/QueryPlanWalker.ts:98

Called once per node during traversal.

Parameters

ParameterTypeDescription
nodeIQueryNodeThe 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.