Skip to content

Commit f5e2736

Browse files
author
Quinn Sinclair
authored
Use Option<Expr> for Min and Max vals in Seq Opts, fix alter col seq display (apache#1106)
1 parent 1b6b6aa commit f5e2736

3 files changed

Lines changed: 21 additions & 38 deletions

File tree

src/ast/ddl.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,13 @@ impl fmt::Display for AlterColumnOperation {
355355

356356
write!(f, "ADD GENERATED{generated_as} AS IDENTITY",)?;
357357
if let Some(options) = sequence_options {
358-
if !options.is_empty() {
359-
write!(f, " (")?;
360-
}
358+
write!(f, " (")?;
361359

362360
for sequence_option in options {
363361
write!(f, "{sequence_option}")?;
364362
}
365363

366-
if !options.is_empty() {
367-
write!(f, " )")?;
368-
}
364+
write!(f, " )")?;
369365
}
370366
Ok(())
371367
}

src/ast/mod.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,8 +3835,8 @@ impl fmt::Display for Statement {
38353835
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
38363836
pub enum SequenceOptions {
38373837
IncrementBy(Expr, bool),
3838-
MinValue(MinMaxValue),
3839-
MaxValue(MinMaxValue),
3838+
MinValue(Option<Expr>),
3839+
MaxValue(Option<Expr>),
38403840
StartWith(Expr, bool),
38413841
Cache(Expr),
38423842
Cycle(bool),
@@ -3853,28 +3853,18 @@ impl fmt::Display for SequenceOptions {
38533853
increment = increment
38543854
)
38553855
}
3856-
SequenceOptions::MinValue(value) => match value {
3857-
MinMaxValue::Empty => {
3858-
write!(f, "")
3859-
}
3860-
MinMaxValue::None => {
3861-
write!(f, " NO MINVALUE")
3862-
}
3863-
MinMaxValue::Some(minvalue) => {
3864-
write!(f, " MINVALUE {minvalue}")
3865-
}
3866-
},
3867-
SequenceOptions::MaxValue(value) => match value {
3868-
MinMaxValue::Empty => {
3869-
write!(f, "")
3870-
}
3871-
MinMaxValue::None => {
3872-
write!(f, " NO MAXVALUE")
3873-
}
3874-
MinMaxValue::Some(maxvalue) => {
3875-
write!(f, " MAXVALUE {maxvalue}")
3876-
}
3877-
},
3856+
SequenceOptions::MinValue(Some(expr)) => {
3857+
write!(f, " MINVALUE {expr}")
3858+
}
3859+
SequenceOptions::MinValue(None) => {
3860+
write!(f, " NO MINVALUE")
3861+
}
3862+
SequenceOptions::MaxValue(Some(expr)) => {
3863+
write!(f, " MAXVALUE {expr}")
3864+
}
3865+
SequenceOptions::MaxValue(None) => {
3866+
write!(f, " NO MAXVALUE")
3867+
}
38783868
SequenceOptions::StartWith(start, with) => {
38793869
write!(
38803870
f,

src/parser/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8805,24 +8805,21 @@ impl<'a> Parser<'a> {
88058805
}
88068806
//[ MINVALUE minvalue | NO MINVALUE ]
88078807
if self.parse_keyword(Keyword::MINVALUE) {
8808-
sequence_options.push(SequenceOptions::MinValue(MinMaxValue::Some(Expr::Value(
8808+
sequence_options.push(SequenceOptions::MinValue(Some(Expr::Value(
88098809
self.parse_number_value()?,
88108810
))));
88118811
} else if self.parse_keywords(&[Keyword::NO, Keyword::MINVALUE]) {
8812-
sequence_options.push(SequenceOptions::MinValue(MinMaxValue::None));
8813-
} else {
8814-
sequence_options.push(SequenceOptions::MinValue(MinMaxValue::Empty));
8812+
sequence_options.push(SequenceOptions::MinValue(None));
88158813
}
88168814
//[ MAXVALUE maxvalue | NO MAXVALUE ]
88178815
if self.parse_keywords(&[Keyword::MAXVALUE]) {
8818-
sequence_options.push(SequenceOptions::MaxValue(MinMaxValue::Some(Expr::Value(
8816+
sequence_options.push(SequenceOptions::MaxValue(Some(Expr::Value(
88198817
self.parse_number_value()?,
88208818
))));
88218819
} else if self.parse_keywords(&[Keyword::NO, Keyword::MAXVALUE]) {
8822-
sequence_options.push(SequenceOptions::MaxValue(MinMaxValue::None));
8823-
} else {
8824-
sequence_options.push(SequenceOptions::MaxValue(MinMaxValue::Empty));
8820+
sequence_options.push(SequenceOptions::MaxValue(None));
88258821
}
8822+
88268823
//[ START [ WITH ] start ]
88278824
if self.parse_keywords(&[Keyword::START]) {
88288825
if self.parse_keywords(&[Keyword::WITH]) {

0 commit comments

Comments
 (0)