Skip to main content

dbmcp_sql_lineage/
error.rs

1//! Error type for lineage extraction.
2
3use thiserror::Error;
4
5/// Failure raised while extracting column lineage from SQL.
6///
7/// Resolution is fail-closed: any projected column that cannot be bound to a
8/// concrete source aborts the whole extraction (see [`LineageError::UnresolvedColumn`]).
9#[derive(Debug, Clone, PartialEq, Eq, Error)]
10pub enum LineageError {
11    /// The SQL string could not be parsed by the selected dialect.
12    #[error("SQL parse error: {0}")]
13    Parse(String),
14
15    /// More than one statement was supplied; only single statements are analyzed.
16    #[error("multi-statement SQL is not supported")]
17    MultiStatement,
18
19    /// A projected column could not be resolved to a concrete source column.
20    #[error("unresolved column `{column}`: {reason}")]
21    UnresolvedColumn {
22        /// The column reference that could not be resolved.
23        column: String,
24        /// Why it could not be resolved (e.g. ambiguous, no catalog).
25        reason: String,
26    },
27
28    /// A referenced table is not present in the supplied schema catalog.
29    #[error("unknown table `{table}`")]
30    UnknownTable {
31        /// The table name that could not be found.
32        table: String,
33    },
34
35    /// Query nesting exceeded the recursion-depth guard.
36    #[error("query nesting depth limit exceeded")]
37    DepthLimitExceeded,
38
39    /// A CTE references itself directly or transitively; lineage is undefined.
40    #[error("circular CTE reference: `{cte}`")]
41    CircularReference {
42        /// The CTE name that re-entered resolution.
43        cte: String,
44    },
45
46    /// A write target's column list does not match its source projection.
47    #[error("column count mismatch for `{target}`: expected {expected}, found {found}")]
48    ColumnCountMismatch {
49        /// The write target table name.
50        target: String,
51        /// Number of explicit target columns.
52        expected: usize,
53        /// Number of source-projection columns.
54        found: usize,
55    },
56}