mapper
Mapper module for converting SQLGlot parsed objects to CLOE metadata models.
AIDEV-NOTE: Maps SQLGlot expression objects (from CREATE TABLE/VIEW) to CLOE metadata models (Database, Schema, Table, Column). Attributes not directly mapped to CLOE model fields are stored in Table.options.
MappingError
¶
MappingResult
¶
Container for mapping results.
Attributes:
| Name | Type | Description |
|---|---|---|
databases |
dict[str | None, Database]
|
Nested CLOE model hierarchy keyed by database (catalog) name.
Each value is a Database -> Schema -> Table -> Column tree.
Extra SQL attributes are stored on each Table via Table.options.
Keys may be |
Source code in src/cloe_delta_table_manager/sql_parser/mapper.py
__init__()
¶
to_databases()
¶
Return the mapped databases as a Databases repository instance.
Runs the Databases uniqueness validator and gives callers access
to lookup helpers like id_to_tables / get_table_and_schema.
Source code in src/cloe_delta_table_manager/sql_parser/mapper.py
export_sqlglot_schema_as_text(expr, output_path=None)
¶
Export SQLGlot expression tree or parsed metadata as readable text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Expression | list[dict[str, Any]]
|
SQLGlot expression object or list of parsed metadata dicts. |
required |
output_path
|
str | None
|
Optional path to write the text file. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
String representation of the SQLGlot schema. |
Source code in src/cloe_delta_table_manager/sql_parser/mapper.py
map_to_cloe_metadata(parsed_metadata, *, catalog=None, schema=None, ignore_missing=False)
¶
Map parsed SQL metadata to CLOE metadata models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parsed_metadata
|
list[dict[str, Any]]
|
List of metadata dictionaries from parse_sql(). |
required |
catalog
|
str | None
|
Override catalog name. When provided and the SQL statement already contains a different catalog, the parameter value wins and a warning is logged. |
None
|
schema
|
str | None
|
Override schema name. Same override/warning logic as catalog. |
None
|
ignore_missing
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
MappingResult
|
MappingResult with databases dict keyed by catalog name. |
MappingResult
|
Extra SQL attributes are stored on each Table via Table.options. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If catalog or schema is missing and
ignore_missing is |