process
High-level wrapper that combines SQL parsing and CLOE metadata mapping.
Provides a single entry-point that accepts a file path, a directory path,
or a raw SQL string, and returns a :class:MappingResult in one call.
process_sql(source_path=None, *, sql=None, dialect='databricks', recursive=False, pattern='*.sql', catalog=None, schema=None, ignore_missing=False)
¶
Parse SQL and map to CLOE metadata in one step.
Provide either source_path (a file or directory) or sql
(a raw SQL string). When both or neither are given a ValueError
is raised.
- If
source_pathpoints to a file, it is read and parsed. - If
source_pathpoints to a directory, every matching SQL file inside it is parsed and the results are merged into one :class:MappingResult. Use recursive and pattern to control which files are included. - If
sqlis given (source_pathmust beNone), the string is parsed directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_path
|
str | Path | None
|
Path to a |
None
|
sql
|
str | None
|
Raw SQL string containing CREATE TABLE / VIEW statements. |
None
|
dialect
|
str
|
SQL dialect for parsing (default: |
'databricks'
|
recursive
|
bool
|
Search subdirectories when source_path is a directory. |
False
|
pattern
|
str
|
Glob pattern for SQL files (default: |
'*.sql'
|
catalog
|
str | None
|
Override catalog name for all statements. |
None
|
schema
|
str | None
|
Override schema name for all statements. |
None
|
ignore_missing
|
bool
|
Accept missing catalog/schema (created with
|
False
|
Returns:
| Type | Description |
|---|---|
MappingResult
|
MappingResult with databases dict keyed by catalog name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both or neither of source_path / sql are given. |
FileNotFoundError
|
If source_path does not exist. |
NotADirectoryError
|
If source_path exists but is neither file nor directory. |
ParseError
|
If the SQL cannot be parsed. |
MappingError
|
If catalog/schema is missing and ignore_missing
is |
Examples:
>>> result = process_sql(sql="CREATE TABLE cat.sch.t (id INT)")
>>> result.databases["cat"].schemas[0].tables[0].name
't'