LucaCappelletti94 commented on code in PR #2096:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2096#discussion_r2524787609
##########
src/parser/mod.rs:
##########
@@ -6422,6 +6431,291 @@ impl<'a> Parser<'a> {
}))
}
+ /// Helper function to parse an operator name (which can contain special
characters)
+ /// Operator names can be schema-qualified (e.g., schema.operator)
+ fn parse_operator_name(&mut self) -> Result<ObjectName, ParserError> {
+ let mut name_parts = vec![];
+ loop {
+ let token = self.next_token();
+ let part =
ObjectNamePart::Identifier(Ident::new(token.to_string()));
+ name_parts.push(part);
+
+ if !self.consume_token(&Token::Period) {
+ break;
+ }
+ }
+ Ok(ObjectName(name_parts))
+ }
+
+ /// Parse a CREATE OPERATOR statement
+ ///
+ /// [PostgreSQL
Documentation](https://www.postgresql.org/docs/current/sql-createoperator.html)
+ pub fn parse_create_operator(&mut self) -> Result<Statement, ParserError> {
+ // Parse the operator name (can be schema-qualified)
+ // Operators can contain special characters like +, -, *, /, <, >, =,
~, !, @, #, %, ^, &, |, `, ?
+ // See https://www.postgresql.org/docs/current/sql-createoperator.html
+ let name = self.parse_operator_name()?;
+
+ // Expect opening parenthesis
+ self.expect_token(&Token::LParen)?;
+
+ let mut function: Option<ObjectName> = None;
+ let mut is_procedure = false;
+ let mut left_arg: Option<DataType> = None;
+ let mut right_arg: Option<DataType> = None;
+ let mut commutator: Option<ObjectName> = None;
+ let mut negator: Option<ObjectName> = None;
+ let mut restrict: Option<ObjectName> = None;
+ let mut join: Option<ObjectName> = None;
+ let mut hashes = false;
+ let mut merges = false;
+
+ loop {
+ // Parse parameter name as keyword
+ let keyword = self.expect_one_of_keywords(&[
+ Keyword::FUNCTION,
+ Keyword::PROCEDURE,
+ Keyword::LEFTARG,
+ Keyword::RIGHTARG,
+ Keyword::COMMUTATOR,
+ Keyword::NEGATOR,
+ Keyword::RESTRICT,
+ Keyword::JOIN,
+ Keyword::HASHES,
+ Keyword::MERGES,
+ ])?;
+
+ // Check if this is a flag (HASHES or MERGES) - no '=' expected
+ match keyword {
+ Keyword::HASHES => {
Review Comment:
Done
--
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]