Skip to content

Commit 74f9207

Browse files
authored
set: allow negative ident values (#495)
Signed-off-by: Maciej Obuchowski <[email protected]>
1 parent 85e0e5f commit 74f9207

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,16 @@ impl<'a> Parser<'a> {
32873287
let value = match (self.parse_value(), token) {
32883288
(Ok(value), _) => SetVariableValue::Literal(value),
32893289
(Err(_), Token::Word(ident)) => SetVariableValue::Ident(ident.to_ident()),
3290+
(Err(_), Token::Minus) => {
3291+
let next_token = self.next_token();
3292+
match next_token {
3293+
Token::Word(ident) => SetVariableValue::Ident(Ident {
3294+
quote_style: ident.quote_style,
3295+
value: format!("-{}", ident.value),
3296+
}),
3297+
_ => self.expected("word", next_token)?,
3298+
}
3299+
}
32903300
(Err(_), unexpected) => self.expected("variable value", unexpected)?,
32913301
};
32923302
values.push(value);

tests/sqlparser_hive.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
//! Test SQL syntax specific to Hive. The parser based on the generic dialect
1616
//! is also tested (on the inputs it can handle).
1717
18+
use sqlparser::ast::{Ident, ObjectName, SetVariableValue, Statement};
1819
use sqlparser::dialect::HiveDialect;
20+
use sqlparser::parser::ParserError;
1921
use sqlparser::test_utils::*;
2022

2123
#[test]
@@ -205,6 +207,31 @@ fn from_cte() {
205207
println!("{}", hive().verified_stmt(rename));
206208
}
207209

210+
#[test]
211+
fn set_statement_with_minus() {
212+
assert_eq!(
213+
hive().verified_stmt("SET hive.tez.java.opts = -Xmx4g"),
214+
Statement::SetVariable {
215+
local: false,
216+
hivevar: false,
217+
variable: ObjectName(vec![
218+
Ident::new("hive"),
219+
Ident::new("tez"),
220+
Ident::new("java"),
221+
Ident::new("opts")
222+
]),
223+
value: vec![SetVariableValue::Ident("-Xmx4g".into())],
224+
}
225+
);
226+
227+
assert_eq!(
228+
hive().parse_sql_statements("SET hive.tez.java.opts = -"),
229+
Err(ParserError::ParserError(
230+
"Expected word, found: EOF".to_string()
231+
))
232+
)
233+
}
234+
208235
fn hive() -> TestedDialects {
209236
TestedDialects {
210237
dialects: vec![Box::new(HiveDialect {})],

0 commit comments

Comments
 (0)