Added support for DROP OPERATOR syntax (#2102)

Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
Luca Cappelletti 2025-11-26 10:51:11 +01:00 committed by GitHub
parent 2ceae006a4
commit 2a2abc8dad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 206 additions and 9 deletions

View file

@ -6767,9 +6767,11 @@ impl<'a> Parser<'a> {
return self.parse_drop_trigger();
} else if self.parse_keyword(Keyword::EXTENSION) {
return self.parse_drop_extension();
} else if self.parse_keyword(Keyword::OPERATOR) {
return self.parse_drop_operator();
} else {
return self.expected(
"CONNECTOR, DATABASE, EXTENSION, FUNCTION, INDEX, POLICY, PROCEDURE, ROLE, SCHEMA, SECRET, SEQUENCE, STAGE, TABLE, TRIGGER, TYPE, VIEW, MATERIALIZED VIEW or USER after DROP",
"CONNECTOR, DATABASE, EXTENSION, FUNCTION, INDEX, OPERATOR, POLICY, PROCEDURE, ROLE, SCHEMA, SECRET, SEQUENCE, STAGE, TABLE, TRIGGER, TYPE, VIEW, MATERIALIZED VIEW or USER after DROP",
self.peek_token(),
);
};
@ -7525,6 +7527,46 @@ impl<'a> Parser<'a> {
}))
}
/// Parse a[Statement::DropOperator] statement.
///
pub fn parse_drop_operator(&mut self) -> Result<Statement, ParserError> {
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
let operators = self.parse_comma_separated(|p| p.parse_drop_operator_signature())?;
let drop_behavior = self.parse_optional_drop_behavior();
Ok(Statement::DropOperator(DropOperator {
if_exists,
operators,
drop_behavior,
}))
}
/// Parse an operator signature for a [Statement::DropOperator]
/// Format: `name ( { left_type | NONE } , right_type )`
fn parse_drop_operator_signature(&mut self) -> Result<DropOperatorSignature, ParserError> {
let name = self.parse_operator_name()?;
self.expect_token(&Token::LParen)?;
// Parse left operand type (or NONE for prefix operators)
let left_type = if self.parse_keyword(Keyword::NONE) {
None
} else {
Some(self.parse_data_type()?)
};
self.expect_token(&Token::Comma)?;
// Parse right operand type (always required)
let right_type = self.parse_data_type()?;
self.expect_token(&Token::RParen)?;
Ok(DropOperatorSignature {
name,
left_type,
right_type,
})
}
//TODO: Implement parsing for Skewed
pub fn parse_hive_distribution(&mut self) -> Result<HiveDistributionStyle, ParserError> {
if self.parse_keywords(&[Keyword::PARTITIONED, Keyword::BY]) {