Skip to content

Commit f3f5c9e

Browse files
committed
refactor by CR
1 parent d441f7d commit f3f5c9e

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/ast/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ pub enum TableFactor {
665665
/// Optional version qualifier to facilitate table time-travel, as
666666
/// supported by BigQuery and MSSQL.
667667
version: Option<TableVersion>,
668-
/// Partition selection, supported by MySQL.
669-
partitions: Vec<Expr>,
668+
/// [Partition selection](https://dev.mysql.com/doc/refman/8.0/en/partitioning-selection.html), supported by MySQL.
669+
partitions: Vec<Ident>,
670670
},
671671
Derived {
672672
lateral: bool,

src/parser/mod.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6210,16 +6210,10 @@ impl<'a> Parser<'a> {
62106210
} else {
62116211
let name = self.parse_object_name()?;
62126212

6213-
let partitions = if dialect_of!(self is MySqlDialect)
6213+
let partitions: Vec<Ident> = if dialect_of!(self is MySqlDialect | GenericDialect)
62146214
&& self.parse_keyword(Keyword::PARTITION)
62156215
{
6216-
let mut partitions = self.parse_comma_separated(|p| p.parse_tuple(true, false))?;
6217-
if partitions.len() != 1 {
6218-
return Err(ParserError::ParserError(format!(
6219-
"Partition expect one tuple"
6220-
)));
6221-
}
6222-
partitions.remove(0)
6216+
self.parse_partitions()?
62236217
} else {
62246218
vec![]
62256219
};
@@ -7430,6 +7424,13 @@ impl<'a> Parser<'a> {
74307424
representation: UserDefinedTypeRepresentation::Composite { attributes },
74317425
})
74327426
}
7427+
7428+
fn parse_partitions(&mut self) -> Result<Vec<Ident>, ParserError> {
7429+
self.expect_token(&Token::LParen)?;
7430+
let partitions = self.parse_comma_separated(Parser::parse_identifier)?;
7431+
self.expect_token(&Token::RParen)?;
7432+
Ok(partitions)
7433+
}
74337434
}
74347435

74357436
impl Word {
@@ -8065,13 +8066,7 @@ mod tests {
80658066
if let TableFactor::Table { partitions, .. } = table_factor {
80668067
let actual: Vec<&str> = partitions
80678068
.iter()
8068-
.map(|expr| {
8069-
if let Expr::Identifier(ident) = &expr {
8070-
ident.value.as_str()
8071-
} else {
8072-
""
8073-
}
8074-
})
8069+
.map(|ident| ident.value.as_str())
80758070
.collect();
80768071
assert_eq!(expected, actual);
80778072
}

0 commit comments

Comments
 (0)