Replace FromStr with normal parser function for FileFormat (#201)

The previous version accepted quoting file format keywords
(`STORED AS "TEXTFILE"`) and was inconsistent with the
way WindowFrameUnits was parsed.
This commit is contained in:
Daniël Heres 2020-06-13 14:38:01 +02:00 committed by GitHub
parent 68afa2a764
commit b24dbe513c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 29 deletions

View file

@ -1006,12 +1006,7 @@ impl Parser {
let table_name = self.parse_object_name()?;
let (columns, constraints) = self.parse_columns()?;
self.expect_keywords(&[Keyword::STORED, Keyword::AS])?;
// We probably shouldn't parse the file format as an identifier..
let file_format = self
.parse_identifier()?
.value
.to_ascii_uppercase()
.parse::<FileFormat>()?;
let file_format = self.parse_file_format()?;
self.expect_keyword(Keyword::LOCATION)?;
let location = self.parse_literal_string()?;
@ -1028,6 +1023,22 @@ impl Parser {
})
}
pub fn parse_file_format(&mut self) -> Result<FileFormat, ParserError> {
match self.next_token() {
Token::Word(w) => match w.keyword {
Keyword::AVRO => Ok(FileFormat::AVRO),
Keyword::JSONFILE => Ok(FileFormat::JSONFILE),
Keyword::ORC => Ok(FileFormat::ORC),
Keyword::PARQUET => Ok(FileFormat::PARQUET),
Keyword::RCFILE => Ok(FileFormat::RCFILE),
Keyword::SEQUENCEFILE => Ok(FileFormat::SEQUENCEFILE),
Keyword::TEXTFILE => Ok(FileFormat::TEXTFILE),
_ => self.expected("fileformat", Token::Word(w)),
},
unexpected => self.expected("fileformat", unexpected),
}
}
pub fn parse_create_view(&mut self) -> Result<Statement, ParserError> {
let materialized = self.parse_keyword(Keyword::MATERIALIZED);
self.expect_keyword(Keyword::VIEW)?;