Skip to content

Commit f287cec

Browse files
committed
refactor by CR
1 parent d441f7d commit f287cec

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-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: 34 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,37 @@ impl<'a> Parser<'a> {
74307424
representation: UserDefinedTypeRepresentation::Composite { attributes },
74317425
})
74327426
}
7427+
7428+
fn parse_partitions(&mut self) -> Result<Vec<Ident>, ParserError> {
7429+
let mut partition_exprs: Vec<Expr> = self.parse_comma_separated(Parser::parse_expr)?;
7430+
7431+
if partition_exprs.len() == 1 {
7432+
match partition_exprs.remove(0) {
7433+
Expr::Tuple(exprs) => {
7434+
let mut partitions: Vec<Ident> = Vec::with_capacity(exprs.len());
7435+
for expr in exprs {
7436+
match expr {
7437+
Expr::Identifier(ident) => partitions.push(ident.clone()),
7438+
_ => {
7439+
return Err(ParserError::ParserError(
7440+
"Partition expect one identifier".to_string(),
7441+
));
7442+
}
7443+
}
7444+
}
7445+
return Ok(partitions);
7446+
}
7447+
_ => {
7448+
return Err(ParserError::ParserError(
7449+
"Partition expect one tuple".to_string(),
7450+
));
7451+
}
7452+
}
7453+
}
7454+
Err(ParserError::ParserError(
7455+
"Partition expect one tuple".to_string(),
7456+
))
7457+
}
74337458
}
74347459

74357460
impl Word {
@@ -8065,13 +8090,7 @@ mod tests {
80658090
if let TableFactor::Table { partitions, .. } = table_factor {
80668091
let actual: Vec<&str> = partitions
80678092
.iter()
8068-
.map(|expr| {
8069-
if let Expr::Identifier(ident) = &expr {
8070-
ident.value.as_str()
8071-
} else {
8072-
""
8073-
}
8074-
})
8093+
.map(|ident| ident.value.as_str())
80758094
.collect();
80768095
assert_eq!(expected, actual);
80778096
}

0 commit comments

Comments
 (0)