diff --git a/src/ast/mod.rs b/src/ast/mod.rs index fe5cba0de..cab337920 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -835,29 +835,6 @@ impl fmt::Display for FileFormat { } } -use crate::parser::ParserError; -use std::str::FromStr; -impl FromStr for FileFormat { - type Err = ParserError; - - fn from_str(s: &str) -> Result { - use self::FileFormat::*; - match s { - "TEXTFILE" => Ok(TEXTFILE), - "SEQUENCEFILE" => Ok(SEQUENCEFILE), - "ORC" => Ok(ORC), - "PARQUET" => Ok(PARQUET), - "AVRO" => Ok(AVRO), - "RCFILE" => Ok(RCFILE), - "JSONFILE" => Ok(JSONFILE), - _ => Err(ParserError::ParserError(format!( - "Unexpected file format: {}", - s - ))), - } - } -} - /// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] [, ] [ON OVERFLOW ] ) ) /// [ WITHIN GROUP (ORDER BY [, ...] ) ]` #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/src/dialect/keywords.rs b/src/dialect/keywords.rs index e804f3693..f5e75f74c 100644 --- a/src/dialect/keywords.rs +++ b/src/dialect/keywords.rs @@ -84,6 +84,7 @@ define_keywords!( ATOMIC, AUTHORIZATION, AVG, + AVRO, BEGIN, BEGIN_FRAME, BEGIN_PARTITION, @@ -231,6 +232,7 @@ define_keywords!( IS, ISOLATION, JOIN, + JSONFILE, KEY, LAG, LANGUAGE, @@ -291,6 +293,7 @@ define_keywords!( ONLY, OPEN, OR, + ORC, ORDER, OUT, OUTER, @@ -318,6 +321,7 @@ define_keywords!( PROCEDURE, RANGE, RANK, + RCFILE, READ, READS, REAL, @@ -356,6 +360,7 @@ define_keywords!( SECOND, SELECT, SENSITIVE, + SEQUENCEFILE, SERIALIZABLE, SESSION, SESSION_USER, @@ -389,6 +394,7 @@ define_keywords!( TABLE, TABLESAMPLE, TEXT, + TEXTFILE, THEN, TIES, TIME, diff --git a/src/parser.rs b/src/parser.rs index 4993eb29a..1763afb49 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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::()?; + 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 { + 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 { let materialized = self.parse_keyword(Keyword::MATERIALIZED); self.expect_keyword(Keyword::VIEW)?;