mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-18 03:39:45 +00:00
hive: add create function syntax (#496)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
parent
0fa812bd2b
commit
cc2559c097
4 changed files with 128 additions and 2 deletions
|
@ -15,8 +15,8 @@
|
|||
//! Test SQL syntax specific to Hive. The parser based on the generic dialect
|
||||
//! is also tested (on the inputs it can handle).
|
||||
|
||||
use sqlparser::ast::{Ident, ObjectName, SetVariableValue, Statement};
|
||||
use sqlparser::dialect::HiveDialect;
|
||||
use sqlparser::ast::{CreateFunctionUsing, Ident, ObjectName, SetVariableValue, Statement};
|
||||
use sqlparser::dialect::{GenericDialect, HiveDialect};
|
||||
use sqlparser::parser::ParserError;
|
||||
use sqlparser::test_utils::*;
|
||||
|
||||
|
@ -232,6 +232,47 @@ fn set_statement_with_minus() {
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_function() {
|
||||
let sql = "CREATE TEMPORARY FUNCTION mydb.myfunc AS 'org.random.class.Name' USING JAR 'hdfs://somewhere.com:8020/very/far'";
|
||||
match hive().verified_stmt(sql) {
|
||||
Statement::CreateFunction {
|
||||
temporary,
|
||||
name,
|
||||
class_name,
|
||||
using,
|
||||
} => {
|
||||
assert!(temporary);
|
||||
assert_eq!("mydb.myfunc", name.to_string());
|
||||
assert_eq!("org.random.class.Name", class_name);
|
||||
assert_eq!(
|
||||
using,
|
||||
Some(CreateFunctionUsing::Jar(
|
||||
"hdfs://somewhere.com:8020/very/far".to_string()
|
||||
))
|
||||
)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let generic = TestedDialects {
|
||||
dialects: vec![Box::new(GenericDialect {})],
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
generic.parse_sql_statements(sql).unwrap_err(),
|
||||
ParserError::ParserError(
|
||||
"Expected an object type after CREATE, found: FUNCTION".to_string()
|
||||
)
|
||||
);
|
||||
|
||||
let sql = "CREATE TEMPORARY FUNCTION mydb.myfunc AS 'org.random.class.Name' USING JAR";
|
||||
assert_eq!(
|
||||
hive().parse_sql_statements(sql).unwrap_err(),
|
||||
ParserError::ParserError("Expected literal string, found: EOF".to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
fn hive() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(HiveDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue