Skip to content

feat: wire QueryExpr algebra pipeline into handle_plan — optimizer, SketchAllocator, PlanSummary (#109 follow-up) - #111

Merged
zzylol merged 1 commit into
mainfrom
109-wire-allocator-plan-summary-direct-parsers
Apr 1, 2026
Merged

zzylol merged 1 commit into
mainfrom
109-wire-allocator-plan-summary-direct-parsers

Conversation

@zzylol

@zzylol zzylol commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • parse_query_expr added to query_parser/mod.rs — dispatches to parse_promql_expr / parse_sql_expr which emit QueryExpr directly from the AST (no lossy SketchExpr round-trip), preserving HistogramQuantile, PromQLSubquery, vector-binary-op matching, Sort+Limit, Join, and SetOp
  • handle_plan now runs the full algebra pipeline when query_string is present: parse_query_expr → QueryOptimizer → SketchAllocator → PlanSummary; the plan_summary key is included in the /api/v1/plan JSON response (stage assignments, bandwidth saved, budget demotions, per-node rationale)
  • Compilation fixes for the new direct-emit path: TokenType(u8) match via .id(), AggItem alias conflict (AlgAggItem), CrossJoin(_) tuple variant, SetOperator::Minus coverage, duplicate SourceSpec import, wc move-before-use in handle_plan

Partially addresses #109 (parser bridge gap + PlanSummary; coverage gap tasks remain open)

New response fields (/api/v1/plan when query_string is supplied)

{
  "plan_summary": {
    "bandwidth_saved_bytes_per_sec": 12345.6,
    "agent_memory_bytes": 65536.0,
    "backend_memory_bytes": 0.0,
    "has_budget_demotion": false,
    "node_annotations": [
      { "node_kind": "SketchAgg", "stage": "agent", "mode": "sketch",
        "rationale": "DDSketch quantile at agent", "memory_bytes": 65536.0, "bytes_per_sec": 800.0 },
      ...
    ]
  }
}

plan_summary is null when query_string is absent or the parser fails (non-fatal warning logged).

Test plan

  • cargo build — clean (0 errors, 13 expected warnings)
  • cargo test — 285 passed, 0 failed
  • Integration: POST /api/v1/plan with query_string: "quantile_over_time(0.99, latency[5m])" returns plan_summary with at least one agent-stage sketch node
  • Integration: POST /api/v1/plan without query_string returns plan_summary: null (no regression)

🤖 Generated with Claude Code

…, direct-emit QueryExpr from parsers

- parse_query_expr() in query_parser/mod.rs dispatches to parse_promql_expr / parse_sql_expr
  which emit QueryExpr directly (no SketchExpr round-trip), preserving HistogramQuantile,
  PromQLSubquery, BinaryOp-VectorMatch, Sort+Limit, Join, SetOp
- handle_plan runs parse_query_expr → QueryOptimizer → SketchAllocator when query_string
  is present; plan_summary (stage assignments, bandwidth saved, budget demotions) is
  included in the /api/v1/plan JSON response
- Fix: TokenType(u8) match via .id(), AggItem alias conflict, CrossJoin(_) tuple variant,
  SetOperator::Minus coverage, duplicate SourceSpec import, wc move-before-use

Closes #109

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zzylol zzylol changed the title SP-9: wire SketchAllocator into handle_plan, expose PlanSummary, direct-emit QueryExpr from parsers feat: wire QueryExpr algebra pipeline into handle_plan — optimizer, SketchAllocator, PlanSummary (#109 follow-up) Apr 1, 2026
@zzylol
zzylol merged commit c19ced1 into main Apr 1, 2026
@zzylol
zzylol deleted the 109-wire-allocator-plan-summary-direct-parsers branch April 1, 2026 16:19
SieDeta pushed a commit that referenced this pull request Apr 17, 2026
…, direct-emit QueryExpr from parsers (#111)

- parse_query_expr() in query_parser/mod.rs dispatches to parse_promql_expr / parse_sql_expr
  which emit QueryExpr directly (no SketchExpr round-trip), preserving HistogramQuantile,
  PromQLSubquery, BinaryOp-VectorMatch, Sort+Limit, Join, SetOp
- handle_plan runs parse_query_expr → QueryOptimizer → SketchAllocator when query_string
  is present; plan_summary (stage assignments, bandwidth saved, budget demotions) is
  included in the /api/v1/plan JSON response
- Fix: TokenType(u8) match via .id(), AggItem alias conflict, CrossJoin(_) tuple variant,
  SetOperator::Minus coverage, duplicate SourceSpec import, wc move-before-use

Closes #109

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant