Skip to main content

Module schema

Module schema 

Source
Expand description

Schema management system for schema-aware analysis and optimization.

Provides a Schema trait and MappingSchema implementation analogous to Python sqlglot’s MappingSchema. This is the foundation for type annotation, column qualification, projection pushdown, and lineage analysis.

§Example

use sqlglot_rust::schema::{MappingSchema, Schema};
use sqlglot_rust::ast::DataType;
use sqlglot_rust::Dialect;

let mut schema = MappingSchema::new(Dialect::Ansi);
schema.add_table(
    &["catalog", "db", "users"],
    vec![
        ("id".to_string(), DataType::Int),
        ("name".to_string(), DataType::Varchar(Some(255))),
        ("email".to_string(), DataType::Text),
    ],
).unwrap();

assert_eq!(
    schema.column_names(&["catalog", "db", "users"]).unwrap(),
    vec!["id", "name", "email"],
);
assert_eq!(
    schema.get_column_type(&["catalog", "db", "users"], "id").unwrap(),
    DataType::Int,
);
assert!(schema.has_column(&["catalog", "db", "users"], "id"));

Structs§

MappingSchema
A schema backed by in-memory hash maps, supporting 3-level nesting: catalog → database → table → column → type.

Enums§

SchemaError
Errors specific to schema operations.

Traits§

Schema
Schema trait for schema-aware analysis and optimization.

Functions§

ensure_schema
Build a MappingSchema from a nested map structure.
ensure_schema_nested
Build a MappingSchema from a 3-level nested map: catalog → database → table → column → type.
is_case_sensitive_dialect
Returns true if the dialect treats unquoted identifiers as case-sensitive.
normalize_identifier
Normalize an identifier according to the given dialect’s conventions.

Type Aliases§

CatalogMap
Type alias for the 3-level nested schema map: catalog → database → table → column → type.