apache / datafusion-sqlparser-rs

Extensible SQL Lexer and Parser for Rust
Apache License 2.0
2.79k stars 537 forks source link

Allow to override all the `parser..` methods. #1415

Open mamcx opened 2 months ago

mamcx commented 2 months ago

We are building a new RDBMS that still has only partial support for the full SQL dialect of Postgres.

This means that we need to parse the strings, and then rule out everything we still do not support. It will be easier and probably faster if we can do:

  // As is possible here
    pub fn parse_statement(&mut self) -> Result<Statement, ParserError> {
        let _guard = self.recursion_counter.try_decrease()?;

        // allow the dialect to override statement parsing
        if let Some(statement) = self.dialect.parse_statement(self) {
            return statement;
        }
   ....
   }

// Make at least the major components overridable:
    pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError> {
        if let Some(result) = self.dialect.parse_table_and_joins(self) {
            return result;
        }
...
...
alamb commented 2 months ago

you could also potentially check the parse tree for structures you don't support and error if you find them (this is the approach we take in DataFusion and it works well) -- basically match on the structures you support and return a Not implemented error for anyting else