File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -3287,6 +3287,16 @@ impl<'a> Parser<'a> {
3287
3287
let value = match ( self . parse_value ( ) , token) {
3288
3288
( Ok ( value) , _) => SetVariableValue :: Literal ( value) ,
3289
3289
( 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
+ }
3290
3300
( Err ( _) , unexpected) => self . expected ( "variable value" , unexpected) ?,
3291
3301
} ;
3292
3302
values. push ( value) ;
Original file line number Diff line number Diff line change 15
15
//! Test SQL syntax specific to Hive. The parser based on the generic dialect
16
16
//! is also tested (on the inputs it can handle).
17
17
18
+ use sqlparser:: ast:: { Ident , ObjectName , SetVariableValue , Statement } ;
18
19
use sqlparser:: dialect:: HiveDialect ;
20
+ use sqlparser:: parser:: ParserError ;
19
21
use sqlparser:: test_utils:: * ;
20
22
21
23
#[ test]
@@ -205,6 +207,31 @@ fn from_cte() {
205
207
println ! ( "{}" , hive( ) . verified_stmt( rename) ) ;
206
208
}
207
209
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
+
208
235
fn hive ( ) -> TestedDialects {
209
236
TestedDialects {
210
237
dialects : vec ! [ Box :: new( HiveDialect { } ) ] ,
You can’t perform that action at this time.
0 commit comments