Skip to main content

laminar_sql/
lib.rs

1//! # `LaminarDB` SQL
2//!
3//! SQL interface for `LaminarDB` with streaming extensions.
4//!
5//! This crate provides:
6//! - SQL parsing with streaming extensions (windows, watermarks, EMIT)
7//! - Query planning and optimization via `DataFusion`
8//! - Streaming-aware physical operators
9//! - SQL-to-operator translation
10//!
11//! ## Streaming SQL Extensions
12//!
13//! ```sql
14//! -- Tumbling window with EMIT
15//! SELECT
16//!   window_start,
17//!   COUNT(*) as event_count
18//! FROM events
19//! GROUP BY TUMBLE(event_time, INTERVAL '5' MINUTE)
20//! EMIT AFTER WATERMARK;
21//!
22//! -- Stream-to-stream join
23//! SELECT *
24//! FROM orders o
25//! JOIN order_items i
26//!   ON o.order_id = i.order_id
27//!   AND i.event_time BETWEEN o.event_time AND o.event_time + INTERVAL '1' HOUR;
28//! ```
29
30#![deny(missing_docs)]
31#![warn(clippy::all, clippy::pedantic)]
32#![allow(clippy::module_name_repetitions)]
33#![allow(clippy::doc_markdown)]
34#![allow(clippy::uninlined_format_args)]
35
36pub mod datafusion;
37pub mod parser;
38pub mod planner;
39pub mod translator;
40
41// Re-export key types
42pub use parser::{parse_streaming_sql, StreamingStatement};
43pub use planner::StreamingPlanner;
44pub use translator::{OrderOperatorConfig, WindowOperatorConfig, WindowType};
45
46// Re-export F005B types
47pub use datafusion::execute::execute_streaming_sql;
48pub use datafusion::{
49    register_streaming_functions, register_streaming_functions_with_watermark, DdlResult,
50    QueryResult, StreamingSqlResult,
51};
52
53/// Result type for SQL operations
54pub type Result<T> = std::result::Result<T, Error>;
55
56/// SQL-specific errors
57#[derive(Debug, thiserror::Error)]
58pub enum Error {
59    /// SQL parsing error
60    #[error("SQL parse error: {0}")]
61    ParseError(#[from] parser::ParseError),
62
63    /// Planning error
64    #[error("Planning error: {0}")]
65    PlanningError(#[from] planner::PlanningError),
66
67    /// `DataFusion` error
68    #[error("DataFusion error: {0}")]
69    DataFusionError(#[from] datafusion_common::DataFusionError),
70
71    /// Unsupported SQL feature
72    #[error("Unsupported feature: {0}")]
73    UnsupportedFeature(String),
74}