Skip to main content

laminar_sql/
lib.rs

1//! LaminarDB SQL parser, planner, and DataFusion integration.
2
3#![deny(missing_docs)]
4#![warn(clippy::all, clippy::pedantic)]
5#![allow(clippy::duration_suboptimal_units)] // MSRV 1.85; from_mins/from_hours are 1.91+
6#![allow(clippy::module_name_repetitions)]
7#![allow(clippy::too_many_arguments, clippy::too_many_lines)] // Parser and planner entry points keep grammar state and operands explicit.
8#![allow(clippy::disallowed_types)] // cold path: SQL parsing and query planning only
9#![allow(clippy::doc_markdown)]
10#![allow(clippy::uninlined_format_args)]
11// Assert cardinality without requiring equality on fixture elements.
12#![cfg_attr(test, allow(clippy::assert_is_empty))]
13
14pub mod datafusion;
15pub mod error;
16pub mod parser;
17pub mod planner;
18pub mod temporal;
19pub mod translator;
20
21// Re-export key types
22pub use parser::{parse_streaming_sql, StreamingStatement};
23pub use planner::streaming_optimizer::{StreamingPhysicalValidator, StreamingValidatorMode};
24pub use planner::StreamingPlanner;
25pub use translator::{OrderOperatorConfig, WindowOperatorConfig, WindowType};
26
27// Re-export types
28pub use datafusion::execute::execute_streaming_sql;
29pub use datafusion::{
30    base_session_config, create_session_context, create_streaming_context_with_validator,
31    register_streaming_functions, register_streaming_functions_with_watermark, DdlResult,
32    QueryResult, StreamingSqlResult,
33};
34
35/// Result type for SQL operations
36pub type Result<T> = std::result::Result<T, Error>;
37
38/// SQL-specific errors
39#[derive(Debug, thiserror::Error)]
40pub enum Error {
41    /// SQL parsing error
42    ParseError(#[from] parser::ParseError),
43
44    /// Planning error
45    PlanningError(#[from] planner::PlanningError),
46
47    /// `DataFusion` error (translated to user-friendly messages on display)
48    DataFusionError(#[from] datafusion_common::DataFusionError),
49
50    /// Unsupported SQL feature
51    UnsupportedFeature(String),
52}
53
54impl std::fmt::Display for Error {
55    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56        match self {
57            Self::ParseError(e) => write!(f, "SQL parse error: {e}"),
58            Self::PlanningError(e) => write!(f, "Planning error: {e}"),
59            Self::DataFusionError(e) => {
60                let translated = error::translate_datafusion_error(&e.to_string());
61                write!(f, "{translated}")
62            }
63            Self::UnsupportedFeature(msg) => {
64                write!(f, "Unsupported feature: {msg}")
65            }
66        }
67    }
68}