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;
14#[cfg(feature = "generate")]
15use crate::generator::GeneratorConfig;
16use crate::tokens::TokenizerConfig;
17
18/// Dune Analytics dialect (based on Trino)
19pub struct DuneDialect;
20
21impl DialectImpl for DuneDialect {
22    fn dialect_type(&self) -> DialectType {
23        DialectType::Dune
24    }
25
26    fn tokenizer_config(&self) -> TokenizerConfig {
27        // Inherit from Trino
28        let trino = TrinoDialect;
29        // Dune supports hex strings with 0x prefix and X'...' syntax
30        // This is handled at the tokenizer level
31        trino.tokenizer_config()
32    }
33
34    #[cfg(feature = "generate")]
35
36    fn generator_config(&self) -> GeneratorConfig {
37        use crate::generator::IdentifierQuoteStyle;
38        // Inherit from Trino with Dune dialect type
39        GeneratorConfig {
40            identifier_quote: '"',
41            identifier_quote_style: IdentifierQuoteStyle::DOUBLE_QUOTE,
42            dialect: Some(DialectType::Dune),
43            ..Default::default()
44        }
45    }
46
47    #[cfg(feature = "transpile")]
48
49    fn transform_expr(&self, expr: Expression) -> Result<Expression> {
50        // Delegate to Trino for most transformations
51        let trino = TrinoDialect;
52
53        // First apply Trino transformations
54        let transformed = trino.transform_expr(expr)?;
55
56        // Dune-specific transformations can be added here
57        // Currently, the main difference is hex string format (handled in generator)
58        Ok(transformed)
59    }
60}