Skip to main content

polyglot_sql/dialects/
dune.rs

1//! Dune Analytics SQL Dialect
2//!
3//! Dune-specific SQL dialect based on sqlglot patterns.
4//! Dune inherits from Trino with minor differences.
5//!
6//! Key characteristics:
7//! - Based on Trino (uses Trino's tokenizer and generator configs)
8//! - Hex strings use 0x prefix format: 0xABCD
9//! - Supports X'...' hex string syntax for parsing
10
11use super::{DialectImpl, DialectType, TrinoDialect};
12use crate::error::Result;
13use crate::expressions::Expression;
14use crate::generator::GeneratorConfig;
15use crate::tokens::TokenizerConfig;
16
17/// Dune Analytics dialect (based on Trino)
18pub struct DuneDialect;
19
20impl DialectImpl for DuneDialect {
21    fn dialect_type(&self) -> DialectType {
22        DialectType::Dune
23    }
24
25    fn tokenizer_config(&self) -> TokenizerConfig {
26        // Inherit from Trino
27        let trino = TrinoDialect;
28        // Dune supports hex strings with 0x prefix and X'...' syntax
29        // This is handled at the tokenizer level
30        trino.tokenizer_config()
31    }
32
33    fn generator_config(&self) -> GeneratorConfig {
34        use crate::generator::IdentifierQuoteStyle;
35        // Inherit from Trino with Dune dialect type
36        GeneratorConfig {
37            identifier_quote: '"',
38            identifier_quote_style: IdentifierQuoteStyle::DOUBLE_QUOTE,
39            dialect: Some(DialectType::Dune),
40            ..Default::default()
41        }
42    }
43
44    fn transform_expr(&self, expr: Expression) -> Result<Expression> {
45        // Delegate to Trino for most transformations
46        let trino = TrinoDialect;
47
48        // First apply Trino transformations
49        let transformed = trino.transform_expr(expr)?;
50
51        // Dune-specific transformations can be added here
52        // Currently, the main difference is hex string format (handled in generator)
53        Ok(transformed)
54    }
55}