Skip to content

Commit e7d68a3

Browse files
author
Alexander Beedie
committed
Box less-used Enums types
1 parent e81eb14 commit e7d68a3

11 files changed

Lines changed: 223 additions & 227 deletions

src/ast/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,11 +1362,11 @@ pub enum Subscript {
13621362
/// ```
13631363
Slice {
13641364
/// Optional lower bound for the slice (inclusive).
1365-
lower_bound: Option<Expr>,
1365+
lower_bound: Option<Box<Expr>>,
13661366
/// Optional upper bound for the slice (inclusive).
1367-
upper_bound: Option<Expr>,
1367+
upper_bound: Option<Box<Expr>>,
13681368
/// Optional stride for the slice (step size).
1369-
stride: Option<Expr>,
1369+
stride: Option<Box<Expr>>,
13701370
},
13711371
}
13721372

@@ -7686,7 +7686,7 @@ pub enum FunctionArg {
76867686
/// Enabled when `Dialect::supports_named_fn_args_with_expr_name` returns 'true'
76877687
ExprNamed {
76887688
/// The expression used as the argument name.
7689-
name: Expr,
7689+
name: Box<Expr>,
76907690
/// The argument expression or wildcard form.
76917691
arg: FunctionArgExpr,
76927692
/// The operator separating name and value.
@@ -7960,7 +7960,7 @@ pub enum FunctionArgumentClause {
79607960
/// [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/aggregate_functions#array_agg
79617961
OrderBy(Vec<OrderByExpr>),
79627962
/// Specifies a limit for the `ARRAY_AGG` and `ARRAY_CONCAT_AGG` functions on BigQuery.
7963-
Limit(Expr),
7963+
Limit(Box<Expr>),
79647964
/// Specifies the behavior on overflow of the `LISTAGG` function.
79657965
///
79667966
/// See <https://trino.io/docs/current/functions/aggregate.html>.

src/ast/query.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ pub struct Select {
477477
/// and it can be used together with WHERE selection.
478478
///
479479
/// [ClickHouse](https://clickhouse.com/docs/en/sql-reference/statements/select/prewhere)
480-
pub prewhere: Option<Expr>,
480+
pub prewhere: Option<Box<Expr>>,
481481
/// WHERE
482-
pub selection: Option<Expr>,
482+
pub selection: Option<Box<Expr>>,
483483
/// [START WITH ..] CONNECT BY ..
484484
pub connect_by: Vec<ConnectByKind>,
485485
/// GROUP BY
@@ -491,11 +491,11 @@ pub struct Select {
491491
/// SORT BY (Hive)
492492
pub sort_by: Vec<OrderByExpr>,
493493
/// HAVING
494-
pub having: Option<Expr>,
494+
pub having: Option<Box<Expr>>,
495495
/// WINDOW AS
496496
pub named_window: Vec<NamedWindowDefinition>,
497497
/// QUALIFY (Snowflake)
498-
pub qualify: Option<Expr>,
498+
pub qualify: Option<Box<Expr>>,
499499
/// The positioning of QUALIFY and WINDOW clauses differ between dialects.
500500
/// e.g. BigQuery requires that WINDOW comes after QUALIFY, while DUCKDB accepts
501501
/// WINDOW before QUALIFY.
@@ -873,9 +873,9 @@ pub enum SelectItem {
873873
},
874874
/// An expression, followed by a wildcard expansion.
875875
/// e.g. `alias.*`, `STRUCT<STRING>('foo').*`
876-
QualifiedWildcard(SelectItemQualifiedWildcardKind, WildcardAdditionalOptions),
876+
QualifiedWildcard(SelectItemQualifiedWildcardKind, Box<WildcardAdditionalOptions>),
877877
/// An unqualified `*`
878-
Wildcard(WildcardAdditionalOptions),
878+
Wildcard(Box<WildcardAdditionalOptions>),
879879
}
880880

881881
impl fmt::Display for SelectItemQualifiedWildcardKind {
@@ -2855,7 +2855,7 @@ pub struct OrderByExpr {
28552855
/// Ordering options such as `ASC`/`DESC` and `NULLS` behavior.
28562856
pub options: OrderByOptions,
28572857
/// Optional `WITH FILL` clause (ClickHouse extension) which specifies how to fill gaps.
2858-
pub with_fill: Option<WithFill>,
2858+
pub with_fill: Option<Box<WithFill>>,
28592859
}
28602860

28612861
impl From<Ident> for OrderByExpr {

src/parser/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4106,13 +4106,13 @@ impl<'a> Parser<'a> {
41064106
None
41074107
} else {
41084108
// parse expr until we hit a colon (or any token with lower precedence)
4109-
Some(self.parse_subexpr(self.dialect.prec_value(Precedence::Colon))?)
4109+
Some(Box::new(self.parse_subexpr(self.dialect.prec_value(Precedence::Colon))?))
41104110
};
41114111

41124112
// check for end
41134113
if self.consume_token(&Token::RBracket) {
41144114
if let Some(lower_bound) = lower_bound {
4115-
return Ok(Subscript::Index { index: lower_bound });
4115+
return Ok(Subscript::Index { index: *lower_bound });
41164116
};
41174117
return Ok(Subscript::Slice {
41184118
lower_bound,
@@ -4135,7 +4135,7 @@ impl<'a> Parser<'a> {
41354135
});
41364136
} else {
41374137
// parse expr until we hit a colon (or any token with lower precedence)
4138-
Some(self.parse_subexpr(self.dialect.prec_value(Precedence::Colon))?)
4138+
Some(Box::new(self.parse_subexpr(self.dialect.prec_value(Precedence::Colon))?))
41394139
};
41404140

41414141
// check for end
@@ -4152,7 +4152,7 @@ impl<'a> Parser<'a> {
41524152
let stride = if self.consume_token(&Token::RBracket) {
41534153
None
41544154
} else {
4155-
Some(self.parse_expr()?)
4155+
Some(Box::new(self.parse_expr()?))
41564156
};
41574157

41584158
if stride.is_some() {
@@ -14209,13 +14209,13 @@ impl<'a> Parser<'a> {
1420914209

1421014210
let prewhere = if self.dialect.supports_prewhere() && self.parse_keyword(Keyword::PREWHERE)
1421114211
{
14212-
Some(self.parse_expr()?)
14212+
Some(Box::new(self.parse_expr()?))
1421314213
} else {
1421414214
None
1421514215
};
1421614216

1421714217
let selection = if self.parse_keyword(Keyword::WHERE) {
14218-
Some(self.parse_expr()?)
14218+
Some(Box::new(self.parse_expr()?))
1421914219
} else {
1422014220
None
1422114221
};
@@ -14245,7 +14245,7 @@ impl<'a> Parser<'a> {
1424514245
};
1424614246

1424714247
let having = if self.parse_keyword(Keyword::HAVING) {
14248-
Some(self.parse_expr()?)
14248+
Some(Box::new(self.parse_expr()?))
1424914249
} else {
1425014250
None
1425114251
};
@@ -14255,12 +14255,12 @@ impl<'a> Parser<'a> {
1425514255
{
1425614256
let named_windows = self.parse_comma_separated(Parser::parse_named_window)?;
1425714257
if self.parse_keyword(Keyword::QUALIFY) {
14258-
(named_windows, Some(self.parse_expr()?), true)
14258+
(named_windows, Some(Box::new(self.parse_expr()?)), true)
1425914259
} else {
1426014260
(named_windows, None, true)
1426114261
}
1426214262
} else if self.parse_keyword(Keyword::QUALIFY) {
14263-
let qualify = Some(self.parse_expr()?);
14263+
let qualify = Some(Box::new(self.parse_expr()?));
1426414264
if self.parse_keyword(Keyword::WINDOW) {
1426514265
(
1426614266
self.parse_comma_separated(Parser::parse_named_window)?,
@@ -17539,7 +17539,7 @@ impl<'a> Parser<'a> {
1753917539
let operator = p.parse_function_named_arg_operator()?;
1754017540
let arg = p.parse_wildcard_expr()?.into();
1754117541
Ok(FunctionArg::ExprNamed {
17542-
name,
17542+
name: Box::new(name),
1754317543
arg,
1754417544
operator,
1754517545
})
@@ -17670,7 +17670,7 @@ impl<'a> Parser<'a> {
1767017670
}
1767117671

1767217672
if self.parse_keyword(Keyword::LIMIT) {
17673-
clauses.push(FunctionArgumentClause::Limit(self.parse_expr()?));
17673+
clauses.push(FunctionArgumentClause::Limit(Box::new(self.parse_expr()?)));
1767417674
}
1767517675

1767617676
if dialect_of!(self is GenericDialect | BigQueryDialect)
@@ -17763,10 +17763,10 @@ impl<'a> Parser<'a> {
1776317763
match self.parse_wildcard_expr()? {
1776417764
Expr::QualifiedWildcard(prefix, token) => Ok(SelectItem::QualifiedWildcard(
1776517765
SelectItemQualifiedWildcardKind::ObjectName(prefix),
17766-
self.parse_wildcard_additional_options(token.0)?,
17766+
Box::new(self.parse_wildcard_additional_options(token.0)?),
1776717767
)),
1776817768
Expr::Wildcard(token) => Ok(SelectItem::Wildcard(
17769-
self.parse_wildcard_additional_options(token.0)?,
17769+
Box::new(self.parse_wildcard_additional_options(token.0)?),
1777017770
)),
1777117771
Expr::Identifier(v) if v.value.to_lowercase() == "from" && v.quote_style.is_none() => {
1777217772
parser_err!(
@@ -17798,7 +17798,7 @@ impl<'a> Parser<'a> {
1779817798
let wildcard_token = self.get_previous_token().clone();
1779917799
Ok(SelectItem::QualifiedWildcard(
1780017800
SelectItemQualifiedWildcardKind::Expr(expr),
17801-
self.parse_wildcard_additional_options(wildcard_token)?,
17801+
Box::new(self.parse_wildcard_additional_options(wildcard_token)?),
1780217802
))
1780317803
}
1780417804
expr => self
@@ -18041,7 +18041,7 @@ impl<'a> Parser<'a> {
1804118041
let with_fill = if self.dialect.supports_with_fill()
1804218042
&& self.parse_keywords(&[Keyword::WITH, Keyword::FILL])
1804318043
{
18044-
Some(self.parse_with_fill()?)
18044+
Some(Box::new(self.parse_with_fill()?))
1804518045
} else {
1804618046
None
1804718047
};

tests/sqlparser_clickhouse.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn parse_map_access_expr() {
7070
}],
7171
lateral_views: vec![],
7272
prewhere: None,
73-
selection: Some(BinaryOp {
73+
selection: Some(Box::new(BinaryOp {
7474
left: Box::new(BinaryOp {
7575
left: Box::new(Identifier(Ident::new("id"))),
7676
op: BinaryOperator::Eq,
@@ -93,7 +93,7 @@ fn parse_map_access_expr() {
9393
op: BinaryOperator::NotEq,
9494
right: Box::new(Expr::value(Value::SingleQuotedString("foo".to_string()))),
9595
}),
96-
}),
96+
})),
9797
group_by: GroupByExpr::Expressions(vec![], vec![]),
9898
cluster_by: vec![],
9999
distribute_by: vec![],
@@ -1162,23 +1162,23 @@ fn parse_select_order_by_with_fill_interpolate() {
11621162
asc: Some(true),
11631163
nulls_first: Some(true),
11641164
},
1165-
with_fill: Some(WithFill {
1165+
with_fill: Some(Box::new(WithFill {
11661166
from: Some(Expr::value(number("10"))),
11671167
to: Some(Expr::value(number("20"))),
11681168
step: Some(Expr::value(number("2"))),
1169-
}),
1169+
})),
11701170
},
11711171
OrderByExpr {
11721172
expr: Expr::Identifier(Ident::new("lname")),
11731173
options: OrderByOptions {
11741174
asc: Some(false),
11751175
nulls_first: Some(false),
11761176
},
1177-
with_fill: Some(WithFill {
1177+
with_fill: Some(Box::new(WithFill {
11781178
from: Some(Expr::value(number("30"))),
11791179
to: Some(Expr::value(number("40"))),
11801180
step: Some(Expr::value(number("3"))),
1181-
}),
1181+
})),
11821182
},
11831183
]),
11841184
interpolate: Some(Interpolate {
@@ -1248,7 +1248,7 @@ fn parse_with_fill() {
12481248
})
12491249
.as_ref(),
12501250
match select.order_by.expect("ORDER BY expected").kind {
1251-
OrderByKind::Expressions(ref exprs) => exprs[0].with_fill.as_ref(),
1251+
OrderByKind::Expressions(ref exprs) => exprs[0].with_fill.as_deref(),
12521252
_ => None,
12531253
}
12541254
);
@@ -1346,7 +1346,7 @@ fn parse_interpolate_with_empty_body() {
13461346
fn test_prewhere() {
13471347
match clickhouse_and_generic().verified_stmt("SELECT * FROM t PREWHERE x = 1 WHERE y = 2") {
13481348
Statement::Query(query) => {
1349-
let prewhere = query.body.as_select().unwrap().prewhere.as_ref();
1349+
let prewhere = query.body.as_select().unwrap().prewhere.as_deref();
13501350
assert_eq!(
13511351
prewhere,
13521352
Some(&BinaryOp {
@@ -1357,7 +1357,7 @@ fn test_prewhere() {
13571357
)),
13581358
})
13591359
);
1360-
let selection = query.as_ref().body.as_select().unwrap().selection.as_ref();
1360+
let selection = query.as_ref().body.as_select().unwrap().selection.as_deref();
13611361
assert_eq!(
13621362
selection,
13631363
Some(&BinaryOp {
@@ -1374,7 +1374,7 @@ fn test_prewhere() {
13741374

13751375
match clickhouse_and_generic().verified_stmt("SELECT * FROM t PREWHERE x = 1 AND y = 2") {
13761376
Statement::Query(query) => {
1377-
let prewhere = query.body.as_select().unwrap().prewhere.as_ref();
1377+
let prewhere = query.body.as_select().unwrap().prewhere.as_deref();
13781378
assert_eq!(
13791379
prewhere,
13801380
Some(&BinaryOp {

0 commit comments

Comments
 (0)