mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
hive: add support for array<> (#491)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
74f92079ac
commit
7ab30d95b0
2 changed files with 60 additions and 3 deletions
|
@ -23,8 +23,8 @@ mod test_utils;
|
|||
use matches::assert_matches;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{
|
||||
AnsiDialect, BigQueryDialect, GenericDialect, MsSqlDialect, PostgreSqlDialect, SQLiteDialect,
|
||||
SnowflakeDialect,
|
||||
AnsiDialect, BigQueryDialect, GenericDialect, HiveDialect, MsSqlDialect, PostgreSqlDialect,
|
||||
SQLiteDialect, SnowflakeDialect,
|
||||
};
|
||||
use sqlparser::keywords::ALL_KEYWORDS;
|
||||
use sqlparser::parser::{Parser, ParserError};
|
||||
|
@ -1755,6 +1755,53 @@ fn parse_create_table() {
|
|||
.contains("Expected constraint details after CONSTRAINT <name>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_hive_array() {
|
||||
// Parsing [] type arrays does not work in MsSql since [ is used in is_delimited_identifier_start
|
||||
let dialects = TestedDialects {
|
||||
dialects: vec![Box::new(PostgreSqlDialect {}), Box::new(HiveDialect {})],
|
||||
};
|
||||
let sql = "CREATE TABLE IF NOT EXISTS something (key int, val array<int>)";
|
||||
match dialects.one_statement_parses_to(
|
||||
sql,
|
||||
"CREATE TABLE IF NOT EXISTS something (key INT, val INT[])",
|
||||
) {
|
||||
Statement::CreateTable {
|
||||
if_not_exists,
|
||||
name,
|
||||
columns,
|
||||
..
|
||||
} => {
|
||||
assert!(if_not_exists);
|
||||
assert_eq!(name, ObjectName(vec!["something".into()]));
|
||||
assert_eq!(
|
||||
columns,
|
||||
vec![
|
||||
ColumnDef {
|
||||
name: Ident::new("key"),
|
||||
data_type: DataType::Int(None),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
ColumnDef {
|
||||
name: Ident::new("val"),
|
||||
data_type: DataType::Array(Box::new(DataType::Int(None))),
|
||||
collation: None,
|
||||
options: vec![],
|
||||
},
|
||||
],
|
||||
)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let res = parse_sql_statements("CREATE TABLE IF NOT EXISTS something (key int, val array<int)");
|
||||
assert!(res
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains("Expected >, found: )"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_with_multiple_on_delete_in_constraint_fails() {
|
||||
parse_sql_statements(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue