mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-25 00:14:06 +00:00
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:
parent
68afa2a764
commit
b24dbe513c
3 changed files with 23 additions and 29 deletions
|
@ -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)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue