Skip to content

struct literal syntax does not work with custom dialect #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
universalmind303 opened this issue Apr 18, 2024 · 2 comments
Closed

struct literal syntax does not work with custom dialect #1227

universalmind303 opened this issue Apr 18, 2024 · 2 comments

Comments

@universalmind303
Copy link
Contributor

The following should work, but instead fails with Expected an expression:, found: { at Line: 1, Column 8

use sqlparser::dialect::Dialect;

#[derive(Debug)]
pub struct MyDialect;
impl Dialect for MyDialect {
    fn is_identifier_start(&self, ch: char) -> bool {
        ch.is_alphabetic() || ch == '_'
    }

    fn is_identifier_part(&self, ch: char) -> bool {
        ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_'
    }

    fn supports_filter_during_aggregation(&self) -> bool {
        true
    }

    fn supports_group_by_expr(&self) -> bool {
        true
    }

    fn supports_named_fn_args_with_eq_operator(&self) -> bool {
        true
    }
}

fn main() {
    let sql = "select {'a': 1}";
    let dialect = MyDialect;
    let parser = sqlparser::parser::Parser::new(&dialect);
    assert!(parser.try_with_sql(sql).unwrap().parse_statement().is_ok());
}
@universalmind303
Copy link
Contributor Author

FWIW, it seems like this is due to the usage of dialect_of! throughout the parser code.

It seems like either the dialect itself needs to be in control of supported syntaxes, or a custom dialect should just be treated as an extension of GenericDialect.

I think the latter would be a bit easier as dialect_of is used ~100 times, so that would be a lot of functionality to expose to the Dialect trait.

@universalmind303
Copy link
Contributor Author

Looking more closely at the code, it looks like you can "extend" a dialect by implementing the Dialect::dialect method

impl Dialect for MyDialect {
    fn dialect(&self) -> std::any::TypeId {
        std::any::TypeId::of::<sqlparser::dialect::GenericDialect>()
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant