mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Add unit tests.
This commit is contained in:
parent
f0f6082eff
commit
26940920ac
3 changed files with 114 additions and 10 deletions
|
@ -457,6 +457,105 @@ fn parse_create_table() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_external_table() {
|
||||
let sql = String::from(
|
||||
"CREATE EXTERNAL TABLE uk_cities (\
|
||||
name VARCHAR(100) NOT NULL,\
|
||||
lat DOUBLE NULL,\
|
||||
lng DOUBLE NULL)\
|
||||
STORED AS TEXTFILE LOCATION '/tmp/example.csv",
|
||||
);
|
||||
let ast = one_statement_parses_to(
|
||||
&sql,
|
||||
"CREATE EXTERNAL TABLE uk_cities (\
|
||||
name character varying(100) NOT NULL, \
|
||||
lat double, \
|
||||
lng double) \
|
||||
STORED AS TEXTFILE LOCATION '/tmp/example.csv'",
|
||||
);
|
||||
match ast {
|
||||
SQLStatement::SQLCreateExternalTable {
|
||||
name,
|
||||
columns,
|
||||
file_format,
|
||||
location,
|
||||
} => {
|
||||
assert_eq!("uk_cities", name.to_string());
|
||||
assert_eq!(3, columns.len());
|
||||
|
||||
let c_name = &columns[0];
|
||||
assert_eq!("name", c_name.name);
|
||||
assert_eq!(SQLType::Varchar(Some(100)), c_name.data_type);
|
||||
assert_eq!(false, c_name.allow_null);
|
||||
|
||||
let c_lat = &columns[1];
|
||||
assert_eq!("lat", c_lat.name);
|
||||
assert_eq!(SQLType::Double, c_lat.data_type);
|
||||
assert_eq!(true, c_lat.allow_null);
|
||||
|
||||
let c_lng = &columns[2];
|
||||
assert_eq!("lng", c_lng.name);
|
||||
assert_eq!(SQLType::Double, c_lng.data_type);
|
||||
assert_eq!(true, c_lng.allow_null);
|
||||
|
||||
assert_eq!(FileFormat::TEXTFILE, file_format);
|
||||
assert_eq!("/tmp/example.csv", location);
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_external_table_newline() {
|
||||
let sql = String::from(
|
||||
"CREATE EXTERNAL TABLE uk_cities (\
|
||||
name VARCHAR(100) NOT NULL,\
|
||||
lat DOUBLE NULL,\
|
||||
lng DOUBLE NULL)\
|
||||
STORED AS TEXTFILE
|
||||
LOCATION '/tmp/example.csv",
|
||||
);
|
||||
let ast = one_statement_parses_to(
|
||||
&sql,
|
||||
"CREATE EXTERNAL TABLE uk_cities (\
|
||||
name character varying(100) NOT NULL, \
|
||||
lat double, \
|
||||
lng double) \
|
||||
STORED AS TEXTFILE LOCATION '/tmp/example.csv'",
|
||||
);
|
||||
match ast {
|
||||
SQLStatement::SQLCreateExternalTable {
|
||||
name,
|
||||
columns,
|
||||
file_format,
|
||||
location,
|
||||
} => {
|
||||
assert_eq!("uk_cities", name.to_string());
|
||||
assert_eq!(3, columns.len());
|
||||
|
||||
let c_name = &columns[0];
|
||||
assert_eq!("name", c_name.name);
|
||||
assert_eq!(SQLType::Varchar(Some(100)), c_name.data_type);
|
||||
assert_eq!(false, c_name.allow_null);
|
||||
|
||||
let c_lat = &columns[1];
|
||||
assert_eq!("lat", c_lat.name);
|
||||
assert_eq!(SQLType::Double, c_lat.data_type);
|
||||
assert_eq!(true, c_lat.allow_null);
|
||||
|
||||
let c_lng = &columns[2];
|
||||
assert_eq!("lng", c_lng.name);
|
||||
assert_eq!(SQLType::Double, c_lng.data_type);
|
||||
assert_eq!(true, c_lng.allow_null);
|
||||
|
||||
assert_eq!(FileFormat::TEXTFILE, file_format);
|
||||
assert_eq!("/tmp/example.csv", location);
|
||||
}
|
||||
_ => assert!(false),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_scalar_function_in_projection() {
|
||||
let sql = "SELECT sqrt(id) FROM foo";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue