LucaCappelletti94 commented on code in PR #2250:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2250#discussion_r3207501733


##########
src/parser/mod.rs:
##########
@@ -5186,6 +5188,140 @@ impl<'a> Parser<'a> {
         }
     }
 
+    fn parse_text_search_object_type(&mut self) -> 
Result<TextSearchObjectType, ParserError> {
+        match self.expect_one_of_keywords(&[
+            Keyword::DICTIONARY,
+            Keyword::CONFIGURATION,
+            Keyword::TEMPLATE,
+            Keyword::PARSER,
+        ])? {
+            Keyword::DICTIONARY => Ok(TextSearchObjectType::Dictionary),
+            Keyword::CONFIGURATION => Ok(TextSearchObjectType::Configuration),
+            Keyword::TEMPLATE => Ok(TextSearchObjectType::Template),
+            Keyword::PARSER => Ok(TextSearchObjectType::Parser),
+            // unreachable because expect_one_of_keywords used above
+            unexpected_keyword => Err(ParserError::ParserError(format!(
+                "Internal parser error: expected any of {{DICTIONARY, 
CONFIGURATION, TEMPLATE, PARSER}}, got {unexpected_keyword:?}"
+            ))),
+        }
+    }
+
+    /// Parse a PostgreSQL `CREATE TEXT SEARCH ...` statement.
+    pub fn parse_create_text_search(&mut self) -> Result<CreateTextSearch, 
ParserError> {
+        self.expect_keywords(&[Keyword::TEXT, Keyword::SEARCH])?;
+        let object_type = self.parse_text_search_object_type()?;
+        let name = self.parse_object_name(false)?;
+        self.expect_token(&Token::LParen)?;
+        let options = self.parse_comma_separated(Parser::parse_sql_option)?;
+        self.expect_token(&Token::RParen)?;
+        Ok(CreateTextSearch {
+            object_type,
+            name,
+            options,
+        })
+    }
+
+    fn parse_alter_text_search_dictionary_option(
+        &mut self,
+    ) -> Result<AlterTextSearchDictionaryOption, ParserError> {
+        let key = self.parse_identifier()?;
+        let value = if self.consume_token(&Token::Eq) {
+            Some(self.parse_expr()?)
+        } else {
+            None
+        };
+        Ok(AlterTextSearchDictionaryOption { key, value })
+    }
+
+    /// Parse a PostgreSQL `ALTER TEXT SEARCH ...` statement.
+    pub fn parse_alter_text_search(&mut self) -> Result<AlterTextSearch, 
ParserError> {
+        self.expect_keywords(&[Keyword::TEXT, Keyword::SEARCH])?;
+        let object_type = self.parse_text_search_object_type()?;
+        let name = self.parse_object_name(false)?;
+
+        let operation = match object_type {
+            TextSearchObjectType::Dictionary => {
+                if self.parse_keywords(&[Keyword::RENAME, Keyword::TO]) {
+                    AlterTextSearchOperation::RenameTo {
+                        new_name: self.parse_identifier()?,
+                    }
+                } else if self.parse_keywords(&[Keyword::OWNER, Keyword::TO]) {
+                    AlterTextSearchOperation::OwnerTo(self.parse_owner()?)
+                } else if self.parse_keywords(&[Keyword::SET, 
Keyword::SCHEMA]) {
+                    AlterTextSearchOperation::SetSchema {
+                        schema_name: self.parse_object_name(false)?,
+                    }
+                } else if self.consume_token(&Token::LParen) {
+                    let options = self
+                        
.parse_comma_separated(Parser::parse_alter_text_search_dictionary_option)?;
+                    self.expect_token(&Token::RParen)?;
+                    AlterTextSearchOperation::SetOptions { options }
+                } else {
+                    return self.expected_ref(
+                        "RENAME TO, OWNER TO, SET SCHEMA, or (...) after ALTER 
TEXT SEARCH DICTIONARY",
+                        self.peek_token_ref(),
+                    );
+                }
+            }
+            TextSearchObjectType::Configuration => {
+                if self.parse_keywords(&[Keyword::RENAME, Keyword::TO]) {
+                    AlterTextSearchOperation::RenameTo {
+                        new_name: self.parse_identifier()?,
+                    }
+                } else if self.parse_keywords(&[Keyword::OWNER, Keyword::TO]) {
+                    AlterTextSearchOperation::OwnerTo(self.parse_owner()?)
+                } else if self.parse_keywords(&[Keyword::SET, 
Keyword::SCHEMA]) {
+                    AlterTextSearchOperation::SetSchema {
+                        schema_name: self.parse_object_name(false)?,

Review Comment:
   I removed the duplicated per-object operation branches. `ALTER TEXT SEARCH` 
now parses whichever supported operation appears, and downstream crates can 
apply stricter validation if they need it.



-- 
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]

Reply via email to