GlobalPlannerNode
Overview
- Builds a deterministic
ExecutionDAGfrom decomposer output. - Creates scan, combine, and post‑combine nodes with explicit edges.
- Sits between
DecomposerNodeandlayer_router. - Class:
GlobalPlannerNode - Source:
packages/nl2sql/src/nl2sql/pipeline/nodes/global_planner/node.py
Responsibilities
- Translate
SubQueryobjects intoscannodes. - Construct
combinenodes for join/union/compare groups. - Construct
post_*nodes for filter/aggregate/project/sort/limit operations. - Create edges between nodes and validate references.
- Compute deterministic
ExecutionDAGordering, content hash, and dag_id.
Position in Execution Graph
Upstream:
- DecomposerNode
Downstream:
- layer_router
Trigger conditions: - Always executed after successful decomposition.
flowchart LR
Decomposer[DecomposerNode] --> Planner[GlobalPlannerNode] --> Router[layer_router]
Inputs
From GraphState:
decomposer_response.sub_queriesdecomposer_response.combine_groupsdecomposer_response.post_combine_ops
Validation performed:
- Validates edges reference existing node IDs.
- Fails if post‑combine ops reference unknown combine groups.
Outputs
Mutations to GraphState:
global_planner_response(GlobalPlannerResponsewithExecutionDAG)reasoningon successerrorson failure
Side effects:
- None beyond in‑memory DAG construction.
Internal Flow (Step-by-Step)
- Extract
sub_queries,combine_groups,post_combine_ops. - For each sub‑query, build a
scanLogicalNodewithRelationSchemafrom expected schema. - For each combine group, create a
combinenode and edges from inputs. - For each post‑combine op, create a
post_*node and edge from its target combine. - Validate that all edges reference known nodes.
- Build
ExecutionDAGwith sorted nodes/edges. - Compute
content_hashanddag_id. - Return
GlobalPlannerResponse. - On exception, emit
PLANNER_FAILEDerror.
Contracts & Interfaces
Implements a LangGraph node callable:
Key contracts:
ExecutionDAGLogicalNode,LogicalEdgeRelationSchema,ColumnSpecGlobalPlannerResponse
Determinism Guarantees
- Nodes and edges are sorted before DAG creation.
ExecutionDAG._layered_toposort()produces stable layer ordering.content_hashis a deterministic hash of nodes/edges/version.
Error Handling
Emits PipelineError with:
PLANNER_FAILEDon exceptions
Logs failures via logger.error.
Retry + Idempotency
- No internal retry logic.
- Deterministic for a given decomposer response.
Performance Characteristics
- Pure in‑memory graph construction and hashing.
- Complexity scales with number of sub‑queries and combine ops.
Observability
- Logger:
global_planner - Adds a reasoning entry on success or failure.
Configuration
- No direct settings read in this node.
Extension Points
- Extend DAG semantics by modifying
kind_mapandattributesmapping. - Replace node in
build_graph()for custom DAG construction.
Known Limitations
- Assumes
expected_schemais present to buildRelationSchema. - No schema validation at DAG construction time.
- No support for custom node kinds without code changes.
Related Code
packages/nl2sql/src/nl2sql/pipeline/nodes/global_planner/node.pypackages/nl2sql/src/nl2sql/pipeline/nodes/global_planner/schemas.py