fv-streams-sql 0.9.0

The SQL front door for FusionVault Streams: a streaming SQL statement parses to a small typed logical plan and lowers to the same topology the TOML frontend produces — one runtime, two front doors. No DataFusion planner, no fork; expressions compile through the value dialect as the steps already do.
Documentation
//! # fv-streams-sql — the SQL front door
//!
//! A streaming SQL statement parses to a **small typed logical plan** ([`plan::Plan`]) and lowers to
//! the *same* [`Topology`] of [`StageDef`](fv_streams_types::StageDef)s the TOML frontend produces (whose `steps` are the engine's
//! own JSON vocabulary). One runtime, two front doors: SQL inherits checkpointing, the exchange,
//! exactness and `--join` because it emits the identical steps a hand-written pipeline would.
//!
//! Deliberately **not** DataFusion's `LogicalPlan`/physical layer (design §10): our own IR models
//! streaming (DataFusion's does not), so there is no fork risk, the errors are streaming-aware and
//! ours, and the IR is the seam a future optimiser plugs into. Scalar expressions lower to the value
//! dialect strings the `expression` steps already carry, compiled through `fv-value-datafusion` at
//! build time exactly as the TOML path does.
//!
//! ```
//! let topo = fv_streams_sql::compile(
//!     "INSERT INTO out SELECT auction, price * 0.908 AS eur FROM bids WHERE type = 'bid'",
//! ).unwrap();
//! assert_eq!(topo.stages.len(), 1);
//! ```

use fv_streams_types::Topology;

mod expr;
mod lower;
mod plan;

pub use plan::Plan;
pub mod reference;

/// Compile one streaming SQL statement into a [`Topology`]. Datasets (the `FROM`/`INSERT INTO`
/// targets) are referenced by name; their bindings (topic, connector, schema) stay in the pipeline
/// config, exactly as the TOML frontend resolves them. Fails LOUDLY with a streaming-aware message
/// on anything outside the supported subset.
pub fn compile(sql: &str) -> Result<Topology, String> {
    let plan = plan::parse(sql)?;
    let plan = optimize(plan);
    let stages = lower::lower(&plan)?;
    Ok(Topology { stages })
}

/// The optimiser seam: passes over the typed IR (filter pushdown, projection pruning, …) go here —
/// streaming-aware because the IR is. Empty today; the boundary exists so a mature optimiser is
/// additive, on our own IR, never a rewrite (design §10).
fn optimize(plan: Plan) -> Plan {
    plan
}

/// Lower a plan to `StageDef`s without wrapping in a `Topology` — for tests that assert the steps.
#[cfg(test)]
pub(crate) fn compile_stages(sql: &str) -> Result<Vec<fv_streams_types::StageDef>, String> {
    lower::lower(&optimize(plan::parse(sql)?))
}

#[cfg(test)]
mod tests;