Skip to main content

laminar_connectors/schema/
mod.rs

1//! Schema inference, resolution, and evolution framework.
2//!
3//! This module implements the foundation of LaminarDB's extensible
4//! connector schema system (F-SCHEMA-001/002/003):
5//!
6//! - **Capability traits** (`traits`) — six opt-in traits that connectors
7//!   implement to declare schema capabilities
8//! - **Schema resolver** (`resolver`) — five-level priority chain for
9//!   determining a source's Arrow schema
10//! - **Format inference** (`inference`) — registry of format-specific
11//!   schema inferencers with built-in JSON, CSV, and raw support
12//! - **Bridge adapters** (`bridge`) — adapters between legacy
13//!   [`RecordDeserializer`](crate::serde::RecordDeserializer) /
14//!   [`RecordSerializer`](crate::serde::RecordSerializer) and the new
15//!   `FormatDecoder` / `FormatEncoder` traits
16//! - **JSON format** (`json`) — JSON decoder, encoder, and JSONB binary
17//!   format (F-SCHEMA-004)
18//! - **CSV format** ([`csv`]) — CSV decoder with DuckDB-style type coercion
19//!   (F-SCHEMA-005)
20//! - **Schema evolution** (`evolution`) — diff, evaluate, and apply schema
21//!   changes with configurable compatibility modes (F-SCHEMA-009)
22//!
23//! # Architecture
24//!
25//! ```text
26//! SourceConnector
27//!   ├── as_schema_provider()      → SchemaProvider
28//!   ├── as_schema_inferable()     → SchemaInferable
29//!   ├── as_schema_registry_aware()→ SchemaRegistryAware
30//!   └── as_schema_evolvable()     → SchemaEvolvable
31//!
32//! SchemaResolver::resolve()
33//!   1. Full DDL         → Declared
34//!   2. Registry         → Registry { schema_id }
35//!   3. Provider         → SourceProvided
36//!   4. Inference        → Inferred { sample_count }
37//!   5. Error
38//! ```
39
40pub mod bridge;
41pub mod csv;
42pub mod error;
43pub mod evolution;
44pub mod inference;
45pub mod json;
46pub mod resolver;
47pub mod traits;
48pub mod types;
49
50#[cfg(any(feature = "parquet-lookup", feature = "files"))]
51pub mod parquet;
52
53// ── Re-exports for convenience ─────────────────────────────────────
54pub use csv::{CsvDecoder, CsvDecoderConfig, FieldCountMismatchStrategy};
55pub use error::{SchemaError, SchemaResult};
56pub use evolution::{
57    diff_schemas_by_name, is_safe_widening, DefaultSchemaEvolver, EvolutionResult,
58    EvolutionTrigger, SchemaEvolutionEngine, SchemaHistory, SchemaHistoryEntry,
59};
60pub use inference::{
61    CsvFormatInference, FormatInference, FormatInferenceRegistry, JsonFormatInference,
62    RawFormatInference, FORMAT_INFERENCE_REGISTRY,
63};
64pub use json::{
65    JsonDecoder, JsonDecoderConfig, JsonEncoder, JsonbAccessor, JsonbEncoder, TypeMismatchStrategy,
66    UnknownFieldStrategy,
67};
68#[cfg(any(feature = "parquet-lookup", feature = "files"))]
69pub use parquet::{
70    ParquetDecoder, ParquetDecoderConfig, ParquetEncoder, ParquetEncoderConfig,
71    ParquetSchemaProvider, RowGroupPredicate,
72};
73pub use resolver::{
74    DeclaredColumn, DeclaredSchema, FieldOrigin, ResolutionKind, ResolvedSchema, SchemaResolver,
75};
76pub use traits::{
77    ArrayInference, ColumnProjection, CompatibilityMode, ConfigOption, ConfigValueType,
78    ConnectorConfigSchema, EvolutionVerdict, FieldInferenceDetail, FormatDecoder, FormatEncoder,
79    InferenceConfig, InferenceWarning, InferredSchema, NumberInference, RegisteredSchema,
80    RegistryConfig, RegistryCredentials, RegistrySchemaType, SchemaChange, SchemaEvolvable,
81    SchemaInferable, SchemaProvider, SchemaRegistryAware, WarningSeverity,
82};
83pub use types::{FieldMeta, RawRecord, SinkConfig, SourceConfig, SourceMetadata};