pub trait DialectImpl {
// Required method
fn dialect_type(&self) -> DialectType;
// Provided methods
fn tokenizer_config(&self) -> TokenizerConfig { ... }
fn generator_config(&self) -> GeneratorConfig { ... }
fn generator_config_for_expr(&self, _expr: &Expression) -> GeneratorConfig { ... }
fn transform_expr(&self, expr: Expression) -> Result<Expression> { ... }
fn preprocess(&self, expr: Expression) -> Result<Expression> { ... }
}Expand description
Trait that each concrete SQL dialect must implement.
DialectImpl provides the configuration hooks and per-expression transform logic
that distinguish one dialect from another. Implementors supply:
- A
DialectTypeidentifier. - Optional overrides for tokenizer and generator configuration (defaults to generic SQL).
- An expression-level transform function (
transform_expr) that rewrites individual AST nodes for this dialect (e.g., convertingNVLtoCOALESCE). - An optional preprocessing step (
preprocess) for whole-tree rewrites that must run before the recursive per-node transform (e.g., eliminating QUALIFY).
The default implementations are no-ops, so a minimal dialect only needs to provide
dialect_type and override the methods that differ from
standard SQL.
Required Methods§
Sourcefn dialect_type(&self) -> DialectType
fn dialect_type(&self) -> DialectType
Returns the DialectType that identifies this dialect.
Provided Methods§
Sourcefn tokenizer_config(&self) -> TokenizerConfig
fn tokenizer_config(&self) -> TokenizerConfig
Returns the tokenizer configuration for this dialect.
Override to customize identifier quoting characters, string escape rules, comment styles, and other lexing behavior.
Sourcefn generator_config(&self) -> GeneratorConfig
fn generator_config(&self) -> GeneratorConfig
Returns the generator configuration for this dialect.
Override to customize identifier quoting style, function name casing, keyword casing, and other SQL generation behavior.
Sourcefn generator_config_for_expr(&self, _expr: &Expression) -> GeneratorConfig
fn generator_config_for_expr(&self, _expr: &Expression) -> GeneratorConfig
Returns a generator configuration tailored to a specific expression.
Override this for hybrid dialects like Athena that route to different SQL engines
based on expression type (e.g., Hive-style generation for DDL, Trino-style for DML).
The default delegates to generator_config.
Sourcefn transform_expr(&self, expr: Expression) -> Result<Expression>
fn transform_expr(&self, expr: Expression) -> Result<Expression>
Transforms a single expression node for this dialect, without recursing into children.
This is the per-node rewrite hook invoked by transform_recursive. Return the
expression unchanged if no dialect-specific rewrite is needed. Transformations
typically include function renaming, operator substitution, and type mapping.
Sourcefn preprocess(&self, expr: Expression) -> Result<Expression>
fn preprocess(&self, expr: Expression) -> Result<Expression>
Applies whole-tree preprocessing transforms before the recursive per-node pass.
Override this to apply structural rewrites that must see the entire tree at once,
such as eliminate_qualify, eliminate_distinct_on, ensure_bools, or
explode_projection_to_unnest. The default is a no-op pass-through.