dlt.destinations.impl.sqlalchemy.dialect
Extensible dialect capabilities for the SqlAlchemy destination.
Users can register custom DialectCapabilities subclasses to adapt the destination for dialects that are not built-in. See register_dialect_capabilities.
GENERIC_TERMINAL_PATTERNS
Terminal patterns for exceptions that don't match undefined-relation but are still non-transient.
DialectCapabilities Objects
class DialectCapabilities()
Base class defining dialect-specific behavior for the SqlAlchemy destination.
Subclass this to adapt the destination for a new SqlAlchemy dialect. Each method corresponds to an extension point:
- adjust_capabilities -- tweak destination capabilities (identifier lengths, timestamp precision, sqlglot dialect, etc.)
- type_mapper_class -- return a custom DataTypeMapper subclass for the dialect
- adapt_table -- modify an sa.Table object before it is materialized (e.g. reorder columns for StarRocks)
- is_undefined_relation -- detect "table/schema not found" errors for the dialect
The sqlglot_dialect property maps backend names to sqlglot dialect names. Override it in subclasses or add entries to SQLGLOT_DIALECTS for non-obvious mappings.
SQLGLOT_DIALECTS
Backend name to sqlglot dialect name. Only entries where the two differ; others fall back to the backend name.
sqlglot_dialect
@property
def sqlglot_dialect() -> str
The sqlglot dialect name for this backend.
Looks up SQLGLOT_DIALECTS first, falls back to the backend name itself.
adjust_capabilities
def adjust_capabilities(caps: DestinationCapabilitiesContext,
dialect: sa.engine.interfaces.Dialect) -> None
Adjust destination capabilities for this dialect.
Called during adjust_capabilities on the factory. Modify caps in-place.
type_mapper_class
def type_mapper_class() -> Type[DataTypeMapper]
Return the type mapper class for this dialect
adapt_table
def adapt_table(table: sa.Table,
table_schema: PreparedTableSchema) -> sa.Table
Modify an sa.Table object before it is created or used for loading.
Return the (possibly modified) table. The default implementation is a no-op.
is_undefined_relation
def is_undefined_relation(e: Exception) -> Optional[bool]
Classify an exception as an undefined-relation error (or not).
The base implementation matches generic patterns that work across many databases. Override in subclasses for dialect-specific error detection.
Returns:
True if the exception represents a missing table/schema, False if it is definitely not such an error, or None to fall through to the built-in pattern matching.
DIALECT_CAPS_REGISTRY
Maps dialect / backend name to the DialectCapabilities class that handles it.
register_dialect_capabilities
def register_dialect_capabilities(
dialect_name: str, caps_class: Type[DialectCapabilities]) -> None
Register a custom DialectCapabilities for a dialect name.
After registration the capabilities are automatically applied when the SqlAlchemy destination connects to a database whose backend name matches dialect_name.
Arguments:
dialect_name- Backend name as returned by SqlalchemyCredentials.get_backend_name() (e.g. "oracle", "starrocks").caps_class- A subclass of DialectCapabilities.
Raises:
ValueError- If caps_class is not a subclass of DialectCapabilities.
get_dialect_capabilities
def get_dialect_capabilities(
dialect_name: str) -> Optional[DialectCapabilities]
Look up previously registered DialectCapabilities instance for a dialect name. Returns None of not found
MysqlDialectCapabilities Objects
class MysqlDialectCapabilities(DialectCapabilities)
Capabilities for MySQL / MariaDB.
TrinoDialectCapabilities Objects
class TrinoDialectCapabilities(DialectCapabilities)
Capabilities for Trino.
MssqlDialectCapabilities Objects
class MssqlDialectCapabilities(DialectCapabilities)
Capabilities for Microsoft SQL Server.
OracleDialectCapabilities Objects
class OracleDialectCapabilities(DialectCapabilities)
Capabilities for Oracle.
DuckdbDialectCapabilities Objects
class DuckdbDialectCapabilities(DialectCapabilities)
Capabilities for DuckDB via duckdb_engine.