Skip to main content
Version: devel

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()

View source on GitHub

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

View source on GitHub

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

View source on GitHub

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]

View source on GitHub

Return the type mapper class for this dialect

adapt_table

def adapt_table(table: sa.Table,
table_schema: PreparedTableSchema) -> sa.Table

View source on GitHub

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]

View source on GitHub

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

View source on GitHub

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]

View source on GitHub

Look up previously registered DialectCapabilities instance for a dialect name. Returns None of not found

MysqlDialectCapabilities Objects

class MysqlDialectCapabilities(DialectCapabilities)

View source on GitHub

Capabilities for MySQL / MariaDB.

TrinoDialectCapabilities Objects

class TrinoDialectCapabilities(DialectCapabilities)

View source on GitHub

Capabilities for Trino.

MssqlDialectCapabilities Objects

class MssqlDialectCapabilities(DialectCapabilities)

View source on GitHub

Capabilities for Microsoft SQL Server.

OracleDialectCapabilities Objects

class OracleDialectCapabilities(DialectCapabilities)

View source on GitHub

Capabilities for Oracle.

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.