Skip to content

Make FileFormat case insensitive #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,12 @@ impl Parser {
let table_name = self.parse_object_name()?;
let (columns, constraints) = self.parse_columns()?;
self.expect_keywords(&[Keyword::STORED, Keyword::AS])?;
let file_format = self.parse_identifier()?.value.parse::<FileFormat>()?;
// We probably shouldn't parse the file format as an identifier..
let file_format = self
.parse_identifier()?
.value
.to_ascii_uppercase()
.parse::<FileFormat>()?;

self.expect_keyword(Keyword::LOCATION)?;
let location = self.parse_literal_string()?;
Expand Down
18 changes: 18 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,24 @@ fn parse_create_external_table() {
}
}

#[test]
fn parse_create_external_table_lowercase() {
let sql = "create external table uk_cities (\
name varchar(100) not null,\
lat double null,\
lng double)\
stored as parquet location '/tmp/example.csv'";
let ast = one_statement_parses_to(
sql,
"CREATE EXTERNAL TABLE uk_cities (\
name character varying(100) NOT NULL, \
lat double NULL, \
lng double) \
STORED AS PARQUET LOCATION '/tmp/example.csv'",
);
assert_matches!(ast, Statement::CreateTable{..});
}

#[test]
fn parse_create_table_empty() {
// Zero-column tables are weird, but supported by at least PostgreSQL.
Expand Down