Skip to main content

DialectImpl

Trait DialectImpl 

Source
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 DialectType identifier.
  • 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., converting NVL to COALESCE).
  • 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§

Source

fn dialect_type(&self) -> DialectType

Returns the DialectType that identifies this dialect.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl DialectImpl for AthenaDialect

Source§

impl DialectImpl for BigQueryDialect

Source§

impl DialectImpl for ClickHouseDialect

Source§

impl DialectImpl for CockroachDBDialect

Source§

impl DialectImpl for DataFusionDialect

Source§

impl DialectImpl for DatabricksDialect

Source§

impl DialectImpl for DorisDialect

Source§

impl DialectImpl for DremioDialect

Source§

impl DialectImpl for DrillDialect

Source§

impl DialectImpl for DruidDialect

Source§

impl DialectImpl for DuckDBDialect

Source§

impl DialectImpl for DuneDialect

Source§

impl DialectImpl for ExasolDialect

Source§

impl DialectImpl for FabricDialect

Source§

impl DialectImpl for GenericDialect

Source§

impl DialectImpl for HanaDialect

Source§

impl DialectImpl for HiveDialect

Source§

impl DialectImpl for MaterializeDialect

Source§

impl DialectImpl for MySQLDialect

Source§

impl DialectImpl for OracleDialect

Source§

impl DialectImpl for PostgresDialect

Source§

impl DialectImpl for PrestoDialect

Source§

impl DialectImpl for RedshiftDialect

Source§

impl DialectImpl for RisingWaveDialect

Source§

impl DialectImpl for SQLiteDialect

Source§

impl DialectImpl for SingleStoreDialect

Source§

impl DialectImpl for SnowflakeDialect

Source§

impl DialectImpl for SolrDialect

Source§

impl DialectImpl for SparkDialect

Source§

impl DialectImpl for StarRocksDialect

Source§

impl DialectImpl for TSQLDialect

Source§

impl DialectImpl for TableauDialect

Source§

impl DialectImpl for TeradataDialect

Source§

impl DialectImpl for TiDBDialect

Source§

impl DialectImpl for TrinoDialect

Source§

impl DialectImpl for VerticaDialect