mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 07:29:11 +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>] ) )
|
/// A `LISTAGG` invocation `LISTAGG( [ DISTINCT ] <expr>[, <separator> ] [ON OVERFLOW <on_overflow>] ) )
|
||||||
/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
|
/// [ WITHIN GROUP (ORDER BY <within_group1>[, ...] ) ]`
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
|
|
@ -84,6 +84,7 @@ define_keywords!(
|
||||||
ATOMIC,
|
ATOMIC,
|
||||||
AUTHORIZATION,
|
AUTHORIZATION,
|
||||||
AVG,
|
AVG,
|
||||||
|
AVRO,
|
||||||
BEGIN,
|
BEGIN,
|
||||||
BEGIN_FRAME,
|
BEGIN_FRAME,
|
||||||
BEGIN_PARTITION,
|
BEGIN_PARTITION,
|
||||||
|
@ -231,6 +232,7 @@ define_keywords!(
|
||||||
IS,
|
IS,
|
||||||
ISOLATION,
|
ISOLATION,
|
||||||
JOIN,
|
JOIN,
|
||||||
|
JSONFILE,
|
||||||
KEY,
|
KEY,
|
||||||
LAG,
|
LAG,
|
||||||
LANGUAGE,
|
LANGUAGE,
|
||||||
|
@ -291,6 +293,7 @@ define_keywords!(
|
||||||
ONLY,
|
ONLY,
|
||||||
OPEN,
|
OPEN,
|
||||||
OR,
|
OR,
|
||||||
|
ORC,
|
||||||
ORDER,
|
ORDER,
|
||||||
OUT,
|
OUT,
|
||||||
OUTER,
|
OUTER,
|
||||||
|
@ -318,6 +321,7 @@ define_keywords!(
|
||||||
PROCEDURE,
|
PROCEDURE,
|
||||||
RANGE,
|
RANGE,
|
||||||
RANK,
|
RANK,
|
||||||
|
RCFILE,
|
||||||
READ,
|
READ,
|
||||||
READS,
|
READS,
|
||||||
REAL,
|
REAL,
|
||||||
|
@ -356,6 +360,7 @@ define_keywords!(
|
||||||
SECOND,
|
SECOND,
|
||||||
SELECT,
|
SELECT,
|
||||||
SENSITIVE,
|
SENSITIVE,
|
||||||
|
SEQUENCEFILE,
|
||||||
SERIALIZABLE,
|
SERIALIZABLE,
|
||||||
SESSION,
|
SESSION,
|
||||||
SESSION_USER,
|
SESSION_USER,
|
||||||
|
@ -389,6 +394,7 @@ define_keywords!(
|
||||||
TABLE,
|
TABLE,
|
||||||
TABLESAMPLE,
|
TABLESAMPLE,
|
||||||
TEXT,
|
TEXT,
|
||||||
|
TEXTFILE,
|
||||||
THEN,
|
THEN,
|
||||||
TIES,
|
TIES,
|
||||||
TIME,
|
TIME,
|
||||||
|
|
|
@ -1006,12 +1006,7 @@ impl Parser {
|
||||||
let table_name = self.parse_object_name()?;
|
let table_name = self.parse_object_name()?;
|
||||||
let (columns, constraints) = self.parse_columns()?;
|
let (columns, constraints) = self.parse_columns()?;
|
||||||
self.expect_keywords(&[Keyword::STORED, Keyword::AS])?;
|
self.expect_keywords(&[Keyword::STORED, Keyword::AS])?;
|
||||||
// We probably shouldn't parse the file format as an identifier..
|
let file_format = self.parse_file_format()?;
|
||||||
let file_format = self
|
|
||||||
.parse_identifier()?
|
|
||||||
.value
|
|
||||||
.to_ascii_uppercase()
|
|
||||||
.parse::<FileFormat>()?;
|
|
||||||
|
|
||||||
self.expect_keyword(Keyword::LOCATION)?;
|
self.expect_keyword(Keyword::LOCATION)?;
|
||||||
let location = self.parse_literal_string()?;
|
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> {
|
pub fn parse_create_view(&mut self) -> Result<Statement, ParserError> {
|
||||||
let materialized = self.parse_keyword(Keyword::MATERIALIZED);
|
let materialized = self.parse_keyword(Keyword::MATERIALIZED);
|
||||||
self.expect_keyword(Keyword::VIEW)?;
|
self.expect_keyword(Keyword::VIEW)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue