iffyio commented on code in PR #2114:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2114#discussion_r2588260906
##########
src/parser/mod.rs:
##########
@@ -9931,6 +9939,114 @@ impl<'a> Parser<'a> {
}
}
+ /// Parse a [Statement::AlterOperator]
+ ///
+ /// [PostgreSQL
Documentation](https://www.postgresql.org/docs/current/sql-alteroperator.html)
+ pub fn parse_alter_operator(&mut self) -> Result<Statement, ParserError> {
+ let name = self.parse_operator_name()?;
+
+ // Parse (left_type, right_type)
+ self.expect_token(&Token::LParen)?;
+
+ let left_type = if self.parse_keyword(Keyword::NONE) {
+ None
+ } else {
+ Some(self.parse_data_type()?)
+ };
+
+ self.expect_token(&Token::Comma)?;
+ let right_type = self.parse_data_type()?;
+ self.expect_token(&Token::RParen)?;
+
+ // Parse the operation
+ let operation = if self.parse_keywords(&[Keyword::OWNER, Keyword::TO])
{
+ let owner = if self.parse_keyword(Keyword::CURRENT_ROLE) {
+ Owner::CurrentRole
+ } else if self.parse_keyword(Keyword::CURRENT_USER) {
+ Owner::CurrentUser
+ } else if self.parse_keyword(Keyword::SESSION_USER) {
+ Owner::SessionUser
+ } else {
+ Owner::Ident(self.parse_identifier()?)
+ };
+ AlterOperatorOperation::OwnerTo(owner)
+ } else if self.parse_keywords(&[Keyword::SET, Keyword::SCHEMA]) {
+ let schema_name = self.parse_object_name(false)?;
+ AlterOperatorOperation::SetSchema { schema_name }
+ } else if self.parse_keyword(Keyword::SET) {
+ self.expect_token(&Token::LParen)?;
+
+ let mut options = Vec::new();
+ loop {
+ let keyword = self.expect_one_of_keywords(&[
+ Keyword::RESTRICT,
+ Keyword::JOIN,
+ Keyword::COMMUTATOR,
+ Keyword::NEGATOR,
+ Keyword::HASHES,
+ Keyword::MERGES,
+ ])?;
+
+ match keyword {
+ Keyword::RESTRICT => {
+ self.expect_token(&Token::Eq)?;
+ let proc_name = if self.parse_keyword(Keyword::NONE) {
+ None
+ } else {
+ Some(self.parse_object_name(false)?)
+ };
+ options.push(OperatorOption::Restrict(proc_name));
+ }
+ Keyword::JOIN => {
+ self.expect_token(&Token::Eq)?;
+ let proc_name = if self.parse_keyword(Keyword::NONE) {
+ None
+ } else {
+ Some(self.parse_object_name(false)?)
+ };
+ options.push(OperatorOption::Join(proc_name));
+ }
+ Keyword::COMMUTATOR => {
+ self.expect_token(&Token::Eq)?;
+ let op_name = self.parse_operator_name()?;
+ options.push(OperatorOption::Commutator(op_name));
+ }
+ Keyword::NEGATOR => {
+ self.expect_token(&Token::Eq)?;
+ let op_name = self.parse_operator_name()?;
+ options.push(OperatorOption::Negator(op_name));
+ }
+ Keyword::HASHES => {
+ options.push(OperatorOption::Hashes);
+ }
+ Keyword::MERGES => {
+ options.push(OperatorOption::Merges);
+ }
+ _ => unreachable!(),
Review Comment:
Can we return an error here instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]