mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-12 15:02:07 +00:00
parent
749b061fbf
commit
7c20d4ae1f
2 changed files with 48 additions and 16 deletions
|
@ -9416,12 +9416,9 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_set(&mut self) -> Result<Statement, ParserError> {
|
/// Parse a `SET ROLE` statement. Expects SET to be consumed already.
|
||||||
let modifier =
|
fn parse_set_role(&mut self, modifier: Option<Keyword>) -> Result<Statement, ParserError> {
|
||||||
self.parse_one_of_keywords(&[Keyword::SESSION, Keyword::LOCAL, Keyword::HIVEVAR]);
|
self.expect_keyword(Keyword::ROLE)?;
|
||||||
if let Some(Keyword::HIVEVAR) = modifier {
|
|
||||||
self.expect_token(&Token::Colon)?;
|
|
||||||
} else if self.parse_keyword(Keyword::ROLE) {
|
|
||||||
let context_modifier = match modifier {
|
let context_modifier = match modifier {
|
||||||
Some(Keyword::LOCAL) => ContextModifier::Local,
|
Some(Keyword::LOCAL) => ContextModifier::Local,
|
||||||
Some(Keyword::SESSION) => ContextModifier::Session,
|
Some(Keyword::SESSION) => ContextModifier::Session,
|
||||||
|
@ -9433,10 +9430,21 @@ impl<'a> Parser<'a> {
|
||||||
} else {
|
} else {
|
||||||
Some(self.parse_identifier(false)?)
|
Some(self.parse_identifier(false)?)
|
||||||
};
|
};
|
||||||
return Ok(Statement::SetRole {
|
Ok(Statement::SetRole {
|
||||||
context_modifier,
|
context_modifier,
|
||||||
role_name,
|
role_name,
|
||||||
});
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_set(&mut self) -> Result<Statement, ParserError> {
|
||||||
|
let modifier =
|
||||||
|
self.parse_one_of_keywords(&[Keyword::SESSION, Keyword::LOCAL, Keyword::HIVEVAR]);
|
||||||
|
if let Some(Keyword::HIVEVAR) = modifier {
|
||||||
|
self.expect_token(&Token::Colon)?;
|
||||||
|
} else if let Some(set_role_stmt) =
|
||||||
|
self.maybe_parse(|parser| parser.parse_set_role(modifier))
|
||||||
|
{
|
||||||
|
return Ok(set_role_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
let variables = if self.parse_keywords(&[Keyword::TIME, Keyword::ZONE]) {
|
let variables = if self.parse_keywords(&[Keyword::TIME, Keyword::ZONE]) {
|
||||||
|
|
|
@ -7665,6 +7665,30 @@ fn parse_set_variable() {
|
||||||
one_statement_parses_to("SET SOMETHING TO '1'", "SET SOMETHING = '1'");
|
one_statement_parses_to("SET SOMETHING TO '1'", "SET SOMETHING = '1'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_set_role_as_variable() {
|
||||||
|
match verified_stmt("SET role = 'foobar'") {
|
||||||
|
Statement::SetVariable {
|
||||||
|
local,
|
||||||
|
hivevar,
|
||||||
|
variables,
|
||||||
|
value,
|
||||||
|
} => {
|
||||||
|
assert!(!local);
|
||||||
|
assert!(!hivevar);
|
||||||
|
assert_eq!(
|
||||||
|
variables,
|
||||||
|
OneOrManyWithParens::One(ObjectName(vec!["role".into()]))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
value,
|
||||||
|
vec![Expr::Value(Value::SingleQuotedString("foobar".into()))]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_double_colon_cast_at_timezone() {
|
fn parse_double_colon_cast_at_timezone() {
|
||||||
let sql = "SELECT '2001-01-01T00:00:00.000Z'::TIMESTAMP AT TIME ZONE 'Europe/Brussels' FROM t";
|
let sql = "SELECT '2001-01-01T00:00:00.000Z'::TIMESTAMP AT TIME ZONE 'Europe/Brussels' FROM t";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue