iffyio commented on code in PR #1808: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1808#discussion_r2051414204
########## src/parser/mod.rs: ########## @@ -5135,6 +5146,63 @@ impl<'a> Parser<'a> { })) } + /// Parse `CREATE FUNCTION` for [SQL Server] + /// + /// [SQL Server]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql + fn parse_mssql_create_function( + &mut self, + or_alter: bool, + or_replace: bool, + temporary: bool, + ) -> Result<Statement, ParserError> { + let name = self.parse_object_name(false)?; + + let parse_function_param = + |parser: &mut Parser| -> Result<OperateFunctionArg, ParserError> { + let name = parser.parse_identifier()?; + let data_type = parser.parse_data_type()?; + Ok(OperateFunctionArg { + mode: None, + name: Some(name), + data_type, + default_expr: None, + }) + }; + self.expect_token(&Token::LParen)?; + let args = self.parse_comma_separated0(parse_function_param, Token::RParen)?; + self.expect_token(&Token::RParen)?; + + let return_type = if self.parse_keyword(Keyword::RETURNS) { + Some(self.parse_data_type()?) + } else { + None + }; + + self.expect_keyword_is(Keyword::AS)?; + self.expect_keyword_is(Keyword::BEGIN)?; + let function_body = Some(CreateFunctionBody::MultiStatement(self.parse_statements()?)); Review Comment: we seem to have some of the related changes left in this codepath? https://github.com/apache/datafusion-sqlparser-rs/blob/6d0ea6462ead65ff598105d8cd44468d972667cb/src/parser/mod.rs#L4458-L4466 ########## src/parser/mod.rs: ########## @@ -15063,6 +15127,15 @@ impl<'a> Parser<'a> { message: Box::new(self.parse_expr()?), })) } + /// Parse [Statement::Return] Review Comment: ```suggestion /// Parse [Statement::Return] ``` ########## tests/sqlparser_common.rs: ########## @@ -15015,3 +15015,8 @@ fn parse_set_time_zone_alias() { _ => unreachable!(), } } + +#[test] +fn parse_return() { + all_dialects().verified_stmt("RETURN"); Review Comment: hmm yeah given that its currently part of the parser behavior I think its reasonable to assert it. If the parser later stops accepting a top-level return value then we would change the test here to assert an error instead ########## src/parser/mod.rs: ########## @@ -5134,6 +5128,76 @@ impl<'a> Parser<'a> { })) } + /// Parse `CREATE FUNCTION` for [MsSql] + /// + /// [MsSql]: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-function-transact-sql + fn parse_mssql_create_function( + &mut self, + or_alter: bool, + or_replace: bool, + temporary: bool, + ) -> Result<Statement, ParserError> { + let (name, args) = self.parse_create_function_name_and_params()?; + + let return_type = if self.parse_keyword(Keyword::RETURNS) { + Some(self.parse_data_type()?) + } else { + return parser_err!("Expected RETURNS keyword", self.peek_token().span.start); + }; Review Comment: ```suggestion self.expect_keyword(Keyword::RETURNS)?; let return_type = Some(self.parse_data_type()?); ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org