Skip to content

Commit

Permalink
feat: add duckdb "INSTALL" and "LOAD" (#1127)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Lamb <[email protected]>
  • Loading branch information
universalmind303 and alamb authored Feb 9, 2024
1 parent d981b09 commit a5ac425
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,20 @@ pub enum Statement {
/// Only for mysql
priority: Option<MysqlInsertPriority>,
},
/// ```sql
/// INSTALL
/// ```
Install {
/// Only for DuckDB
extension_name: Ident,
},
/// ```sql
/// LOAD
/// ```
Load {
/// Only for DuckDB
extension_name: Ident,
},
// TODO: Support ROW FORMAT
Directory {
overwrite: bool,
Expand Down Expand Up @@ -2637,6 +2651,13 @@ impl fmt::Display for Statement {

Ok(())
}
Statement::Install {
extension_name: name,
} => write!(f, "INSTALL {name}"),

Statement::Load {
extension_name: name,
} => write!(f, "LOAD {name}"),

Statement::Call(function) => write!(f, "CALL {function}"),

Expand Down
2 changes: 2 additions & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ define_keywords!(
INPUTFORMAT,
INSENSITIVE,
INSERT,
INSTALL,
INT,
INT2,
INT4,
Expand Down Expand Up @@ -390,6 +391,7 @@ define_keywords!(
LIMIT,
LISTAGG,
LN,
LOAD,
LOCAL,
LOCALTIME,
LOCALTIMESTAMP,
Expand Down
22 changes: 22 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,15 @@ impl<'a> Parser<'a> {
Keyword::MERGE => Ok(self.parse_merge()?),
// `PRAGMA` is sqlite specific https://www.sqlite.org/pragma.html
Keyword::PRAGMA => Ok(self.parse_pragma()?),
// `INSTALL` is duckdb specific https://duckdb.org/docs/extensions/overview
Keyword::INSTALL if dialect_of!(self is DuckDbDialect | GenericDialect) => {
Ok(self.parse_install()?)
}
// `LOAD` is duckdb specific https://duckdb.org/docs/extensions/overview
Keyword::LOAD if dialect_of!(self is DuckDbDialect | GenericDialect) => {
Ok(self.parse_load()?)
}

_ => self.expected("an SQL statement", next_token),
},
Token::LParen => {
Expand Down Expand Up @@ -8791,6 +8800,19 @@ impl<'a> Parser<'a> {
}
}

/// `INSTALL [extension_name]`
pub fn parse_install(&mut self) -> Result<Statement, ParserError> {
let extension_name = self.parse_identifier(false)?;

Ok(Statement::Install { extension_name })
}

/// `LOAD [extension_name]`
pub fn parse_load(&mut self) -> Result<Statement, ParserError> {
let extension_name = self.parse_identifier(false)?;
Ok(Statement::Load { extension_name })
}

/// ```sql
/// CREATE [ { TEMPORARY | TEMP } ] SEQUENCE [ IF NOT EXISTS ] <sequence_name>
/// ```
Expand Down
28 changes: 28 additions & 0 deletions tests/sqlparser_duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,31 @@ fn test_select_union_by_name() {
assert_eq!(ast.body, expected);
}
}

#[test]
fn test_duckdb_install() {
let stmt = duckdb().verified_stmt("INSTALL tpch");
assert_eq!(
stmt,
Statement::Install {
extension_name: Ident {
value: "tpch".to_string(),
quote_style: None
}
}
);
}

#[test]
fn test_duckdb_load_extension() {
let stmt = duckdb().verified_stmt("LOAD my_extension");
assert_eq!(
Statement::Load {
extension_name: Ident {
value: "my_extension".to_string(),
quote_style: None
}
},
stmt
);
}

0 comments on commit a5ac425

Please sign in to comment.