mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-03 22:08:16 +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
|
@ -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<Self, Self::Err> {
|
||||
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 ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
|
||||
/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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