|
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}; |
19 |
| -use sqlparser::dialect::HiveDialect; |
| 18 | +use sqlparser::ast::{CreateFunctionUsing, Ident, ObjectName, SetVariableValue, Statement}; |
| 19 | +use sqlparser::dialect::{GenericDialect, HiveDialect}; |
20 | 20 | use sqlparser::parser::ParserError;
|
21 | 21 | use sqlparser::test_utils::*;
|
22 | 22 |
|
@@ -232,6 +232,47 @@ fn set_statement_with_minus() {
|
232 | 232 | )
|
233 | 233 | }
|
234 | 234 |
|
| 235 | +#[test] |
| 236 | +fn parse_create_function() { |
| 237 | + let sql = "CREATE TEMPORARY FUNCTION mydb.myfunc AS 'org.random.class.Name' USING JAR 'hdfs://somewhere.com:8020/very/far'"; |
| 238 | + match hive().verified_stmt(sql) { |
| 239 | + Statement::CreateFunction { |
| 240 | + temporary, |
| 241 | + name, |
| 242 | + class_name, |
| 243 | + using, |
| 244 | + } => { |
| 245 | + assert!(temporary); |
| 246 | + assert_eq!("mydb.myfunc", name.to_string()); |
| 247 | + assert_eq!("org.random.class.Name", class_name); |
| 248 | + assert_eq!( |
| 249 | + using, |
| 250 | + Some(CreateFunctionUsing::Jar( |
| 251 | + "hdfs://somewhere.com:8020/very/far".to_string() |
| 252 | + )) |
| 253 | + ) |
| 254 | + } |
| 255 | + _ => unreachable!(), |
| 256 | + } |
| 257 | + |
| 258 | + let generic = TestedDialects { |
| 259 | + dialects: vec![Box::new(GenericDialect {})], |
| 260 | + }; |
| 261 | + |
| 262 | + assert_eq!( |
| 263 | + generic.parse_sql_statements(sql).unwrap_err(), |
| 264 | + ParserError::ParserError( |
| 265 | + "Expected an object type after CREATE, found: FUNCTION".to_string() |
| 266 | + ) |
| 267 | + ); |
| 268 | + |
| 269 | + let sql = "CREATE TEMPORARY FUNCTION mydb.myfunc AS 'org.random.class.Name' USING JAR"; |
| 270 | + assert_eq!( |
| 271 | + hive().parse_sql_statements(sql).unwrap_err(), |
| 272 | + ParserError::ParserError("Expected literal string, found: EOF".to_string()), |
| 273 | + ); |
| 274 | +} |
| 275 | + |
235 | 276 | fn hive() -> TestedDialects {
|
236 | 277 | TestedDialects {
|
237 | 278 | dialects: vec![Box::new(HiveDialect {})],
|
|
0 commit comments