mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Add support for LANGUAGE
clause in CREATE PROCEDURE
(#1903)
This commit is contained in:
parent
1bbc05cdff
commit
95d16e3b2d
4 changed files with 46 additions and 1 deletions
|
@ -3945,6 +3945,7 @@ pub enum Statement {
|
||||||
or_alter: bool,
|
or_alter: bool,
|
||||||
name: ObjectName,
|
name: ObjectName,
|
||||||
params: Option<Vec<ProcedureParam>>,
|
params: Option<Vec<ProcedureParam>>,
|
||||||
|
language: Option<Ident>,
|
||||||
body: ConditionalStatements,
|
body: ConditionalStatements,
|
||||||
},
|
},
|
||||||
/// ```sql
|
/// ```sql
|
||||||
|
@ -4848,6 +4849,7 @@ impl fmt::Display for Statement {
|
||||||
name,
|
name,
|
||||||
or_alter,
|
or_alter,
|
||||||
params,
|
params,
|
||||||
|
language,
|
||||||
body,
|
body,
|
||||||
} => {
|
} => {
|
||||||
write!(
|
write!(
|
||||||
|
@ -4863,6 +4865,10 @@ impl fmt::Display for Statement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(language) = language {
|
||||||
|
write!(f, " LANGUAGE {language}")?;
|
||||||
|
}
|
||||||
|
|
||||||
write!(f, " AS {body}")
|
write!(f, " AS {body}")
|
||||||
}
|
}
|
||||||
Statement::CreateMacro {
|
Statement::CreateMacro {
|
||||||
|
|
|
@ -15802,6 +15802,13 @@ impl<'a> Parser<'a> {
|
||||||
pub fn parse_create_procedure(&mut self, or_alter: bool) -> Result<Statement, ParserError> {
|
pub fn parse_create_procedure(&mut self, or_alter: bool) -> Result<Statement, ParserError> {
|
||||||
let name = self.parse_object_name(false)?;
|
let name = self.parse_object_name(false)?;
|
||||||
let params = self.parse_optional_procedure_parameters()?;
|
let params = self.parse_optional_procedure_parameters()?;
|
||||||
|
|
||||||
|
let language = if self.parse_keyword(Keyword::LANGUAGE) {
|
||||||
|
Some(self.parse_identifier()?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
self.expect_keyword_is(Keyword::AS)?;
|
self.expect_keyword_is(Keyword::AS)?;
|
||||||
|
|
||||||
let body = self.parse_conditional_statements(&[Keyword::END])?;
|
let body = self.parse_conditional_statements(&[Keyword::END])?;
|
||||||
|
@ -15810,6 +15817,7 @@ impl<'a> Parser<'a> {
|
||||||
name,
|
name,
|
||||||
or_alter,
|
or_alter,
|
||||||
params,
|
params,
|
||||||
|
language,
|
||||||
body,
|
body,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -15357,6 +15357,36 @@ fn check_enforced() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_create_procedure_with_language() {
|
||||||
|
let sql = r#"CREATE PROCEDURE test_proc LANGUAGE sql AS BEGIN SELECT 1; END"#;
|
||||||
|
match verified_stmt(sql) {
|
||||||
|
Statement::CreateProcedure {
|
||||||
|
or_alter,
|
||||||
|
name,
|
||||||
|
params,
|
||||||
|
language,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
assert_eq!(or_alter, false);
|
||||||
|
assert_eq!(name.to_string(), "test_proc");
|
||||||
|
assert_eq!(params, Some(vec![]));
|
||||||
|
assert_eq!(
|
||||||
|
language,
|
||||||
|
Some(Ident {
|
||||||
|
value: "sql".into(),
|
||||||
|
quote_style: None,
|
||||||
|
span: Span {
|
||||||
|
start: Location::empty(),
|
||||||
|
end: Location::empty()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_create_procedure_with_parameter_modes() {
|
fn parse_create_procedure_with_parameter_modes() {
|
||||||
let sql = r#"CREATE PROCEDURE test_proc (IN a INTEGER, OUT b TEXT, INOUT c TIMESTAMP, d BOOL) AS BEGIN SELECT 1; END"#;
|
let sql = r#"CREATE PROCEDURE test_proc (IN a INTEGER, OUT b TEXT, INOUT c TIMESTAMP, d BOOL) AS BEGIN SELECT 1; END"#;
|
||||||
|
|
|
@ -173,7 +173,8 @@ fn parse_create_procedure() {
|
||||||
value: "test".into(),
|
value: "test".into(),
|
||||||
quote_style: None,
|
quote_style: None,
|
||||||
span: Span::empty(),
|
span: Span::empty(),
|
||||||
}])
|
}]),
|
||||||
|
language: None,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue