mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-27 07:59:11 +00:00
set: allow negative ident values (#495)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
parent
85e0e5fd39
commit
74f92079ac
2 changed files with 37 additions and 0 deletions
|
@ -3287,6 +3287,16 @@ impl<'a> Parser<'a> {
|
||||||
let value = match (self.parse_value(), token) {
|
let value = match (self.parse_value(), token) {
|
||||||
(Ok(value), _) => SetVariableValue::Literal(value),
|
(Ok(value), _) => SetVariableValue::Literal(value),
|
||||||
(Err(_), Token::Word(ident)) => SetVariableValue::Ident(ident.to_ident()),
|
(Err(_), Token::Word(ident)) => SetVariableValue::Ident(ident.to_ident()),
|
||||||
|
(Err(_), Token::Minus) => {
|
||||||
|
let next_token = self.next_token();
|
||||||
|
match next_token {
|
||||||
|
Token::Word(ident) => SetVariableValue::Ident(Ident {
|
||||||
|
quote_style: ident.quote_style,
|
||||||
|
value: format!("-{}", ident.value),
|
||||||
|
}),
|
||||||
|
_ => self.expected("word", next_token)?,
|
||||||
|
}
|
||||||
|
}
|
||||||
(Err(_), unexpected) => self.expected("variable value", unexpected)?,
|
(Err(_), unexpected) => self.expected("variable value", unexpected)?,
|
||||||
};
|
};
|
||||||
values.push(value);
|
values.push(value);
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
//! Test SQL syntax specific to Hive. The parser based on the generic dialect
|
//! Test SQL syntax specific to Hive. The parser based on the generic dialect
|
||||||
//! is also tested (on the inputs it can handle).
|
//! is also tested (on the inputs it can handle).
|
||||||
|
|
||||||
|
use sqlparser::ast::{Ident, ObjectName, SetVariableValue, Statement};
|
||||||
use sqlparser::dialect::HiveDialect;
|
use sqlparser::dialect::HiveDialect;
|
||||||
|
use sqlparser::parser::ParserError;
|
||||||
use sqlparser::test_utils::*;
|
use sqlparser::test_utils::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -205,6 +207,31 @@ fn from_cte() {
|
||||||
println!("{}", hive().verified_stmt(rename));
|
println!("{}", hive().verified_stmt(rename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn set_statement_with_minus() {
|
||||||
|
assert_eq!(
|
||||||
|
hive().verified_stmt("SET hive.tez.java.opts = -Xmx4g"),
|
||||||
|
Statement::SetVariable {
|
||||||
|
local: false,
|
||||||
|
hivevar: false,
|
||||||
|
variable: ObjectName(vec![
|
||||||
|
Ident::new("hive"),
|
||||||
|
Ident::new("tez"),
|
||||||
|
Ident::new("java"),
|
||||||
|
Ident::new("opts")
|
||||||
|
]),
|
||||||
|
value: vec![SetVariableValue::Ident("-Xmx4g".into())],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
hive().parse_sql_statements("SET hive.tez.java.opts = -"),
|
||||||
|
Err(ParserError::ParserError(
|
||||||
|
"Expected word, found: EOF".to_string()
|
||||||
|
))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn hive() -> TestedDialects {
|
fn hive() -> TestedDialects {
|
||||||
TestedDialects {
|
TestedDialects {
|
||||||
dialects: vec![Box::new(HiveDialect {})],
|
dialects: vec![Box::new(HiveDialect {})],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue