mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-22 05:32:29 +00:00
set: allow dots in variables by moving to ObjectName (#484)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
parent
835bb2f9ad
commit
6d057ef4df
3 changed files with 41 additions and 9 deletions
|
@ -921,7 +921,7 @@ pub enum Statement {
|
||||||
SetVariable {
|
SetVariable {
|
||||||
local: bool,
|
local: bool,
|
||||||
hivevar: bool,
|
hivevar: bool,
|
||||||
variable: Ident,
|
variable: ObjectName,
|
||||||
value: Vec<SetVariableValue>,
|
value: Vec<SetVariableValue>,
|
||||||
},
|
},
|
||||||
/// SHOW <variable>
|
/// SHOW <variable>
|
||||||
|
|
|
@ -3266,7 +3266,7 @@ impl<'a> Parser<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let variable = self.parse_identifier()?;
|
let variable = self.parse_object_name()?;
|
||||||
if self.consume_token(&Token::Eq) || self.parse_keyword(Keyword::TO) {
|
if self.consume_token(&Token::Eq) || self.parse_keyword(Keyword::TO) {
|
||||||
let mut values = vec![];
|
let mut values = vec![];
|
||||||
loop {
|
loop {
|
||||||
|
@ -3287,14 +3287,14 @@ impl<'a> Parser<'a> {
|
||||||
value: values,
|
value: values,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if variable.value == "CHARACTERISTICS" {
|
} else if variable.to_string() == "CHARACTERISTICS" {
|
||||||
self.expect_keywords(&[Keyword::AS, Keyword::TRANSACTION])?;
|
self.expect_keywords(&[Keyword::AS, Keyword::TRANSACTION])?;
|
||||||
Ok(Statement::SetTransaction {
|
Ok(Statement::SetTransaction {
|
||||||
modes: self.parse_transaction_modes()?,
|
modes: self.parse_transaction_modes()?,
|
||||||
snapshot: None,
|
snapshot: None,
|
||||||
session: true,
|
session: true,
|
||||||
})
|
})
|
||||||
} else if variable.value == "TRANSACTION" && modifier.is_none() {
|
} else if variable.to_string() == "TRANSACTION" && modifier.is_none() {
|
||||||
if self.parse_keyword(Keyword::SNAPSHOT) {
|
if self.parse_keyword(Keyword::SNAPSHOT) {
|
||||||
let snaphot_id = self.parse_value()?;
|
let snaphot_id = self.parse_value()?;
|
||||||
return Ok(Statement::SetTransaction {
|
return Ok(Statement::SetTransaction {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
mod test_utils;
|
mod test_utils;
|
||||||
use test_utils::*;
|
use test_utils::*;
|
||||||
|
|
||||||
|
use sqlparser::ast::Value::Boolean;
|
||||||
use sqlparser::ast::*;
|
use sqlparser::ast::*;
|
||||||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
||||||
use sqlparser::parser::ParserError;
|
use sqlparser::parser::ParserError;
|
||||||
|
@ -780,7 +781,7 @@ fn parse_set() {
|
||||||
Statement::SetVariable {
|
Statement::SetVariable {
|
||||||
local: false,
|
local: false,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: "a".into(),
|
variable: ObjectName(vec![Ident::new("a")]),
|
||||||
value: vec![SetVariableValue::Ident("b".into())],
|
value: vec![SetVariableValue::Ident("b".into())],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -791,7 +792,7 @@ fn parse_set() {
|
||||||
Statement::SetVariable {
|
Statement::SetVariable {
|
||||||
local: false,
|
local: false,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: "a".into(),
|
variable: ObjectName(vec![Ident::new("a")]),
|
||||||
value: vec![SetVariableValue::Literal(Value::SingleQuotedString(
|
value: vec![SetVariableValue::Literal(Value::SingleQuotedString(
|
||||||
"b".into()
|
"b".into()
|
||||||
))],
|
))],
|
||||||
|
@ -804,7 +805,7 @@ fn parse_set() {
|
||||||
Statement::SetVariable {
|
Statement::SetVariable {
|
||||||
local: false,
|
local: false,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: "a".into(),
|
variable: ObjectName(vec![Ident::new("a")]),
|
||||||
value: vec![SetVariableValue::Literal(number("0"))],
|
value: vec![SetVariableValue::Literal(number("0"))],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -815,7 +816,7 @@ fn parse_set() {
|
||||||
Statement::SetVariable {
|
Statement::SetVariable {
|
||||||
local: false,
|
local: false,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: "a".into(),
|
variable: ObjectName(vec![Ident::new("a")]),
|
||||||
value: vec![SetVariableValue::Ident("DEFAULT".into())],
|
value: vec![SetVariableValue::Ident("DEFAULT".into())],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -826,11 +827,42 @@ fn parse_set() {
|
||||||
Statement::SetVariable {
|
Statement::SetVariable {
|
||||||
local: true,
|
local: true,
|
||||||
hivevar: false,
|
hivevar: false,
|
||||||
variable: "a".into(),
|
variable: ObjectName(vec![Ident::new("a")]),
|
||||||
value: vec![SetVariableValue::Ident("b".into())],
|
value: vec![SetVariableValue::Ident("b".into())],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let stmt = pg_and_generic().verified_stmt("SET a.b.c = b");
|
||||||
|
assert_eq!(
|
||||||
|
stmt,
|
||||||
|
Statement::SetVariable {
|
||||||
|
local: false,
|
||||||
|
hivevar: false,
|
||||||
|
variable: ObjectName(vec![Ident::new("a"), Ident::new("b"), Ident::new("c")]),
|
||||||
|
value: vec![SetVariableValue::Ident("b".into())],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let stmt = pg_and_generic().one_statement_parses_to(
|
||||||
|
"SET hive.tez.auto.reducer.parallelism=false",
|
||||||
|
"SET hive.tez.auto.reducer.parallelism = false",
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
stmt,
|
||||||
|
Statement::SetVariable {
|
||||||
|
local: false,
|
||||||
|
hivevar: false,
|
||||||
|
variable: ObjectName(vec![
|
||||||
|
Ident::new("hive"),
|
||||||
|
Ident::new("tez"),
|
||||||
|
Ident::new("auto"),
|
||||||
|
Ident::new("reducer"),
|
||||||
|
Ident::new("parallelism")
|
||||||
|
]),
|
||||||
|
value: vec![SetVariableValue::Literal(Boolean(false))],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
pg_and_generic().one_statement_parses_to("SET a TO b", "SET a = b");
|
pg_and_generic().one_statement_parses_to("SET a TO b", "SET a = b");
|
||||||
pg_and_generic().one_statement_parses_to("SET SESSION a = b", "SET a = b");
|
pg_and_generic().one_statement_parses_to("SET SESSION a = b", "SET a = b");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue