Skip to content

Commit e9de85d

Browse files
committed
Inline the function wihtout cloning
1 parent 79a91d8 commit e9de85d

File tree

1 file changed

+23
-33
lines changed

1 file changed

+23
-33
lines changed

src/parser/mod.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11181,18 +11181,30 @@ impl<'a> Parser<'a> {
1118111181
self.peek_token().location
1118211182
)
1118311183
}
11184-
expr => {
11185-
if self.dialect.supports_eq_alias_assigment() {
11186-
if let Some(select_item) = Self::maybe_unpack_alias_assignment(&expr) {
11187-
return Ok(select_item);
11188-
}
11189-
}
11190-
self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)
11191-
.map(|alias| match alias {
11192-
Some(alias) => SelectItem::ExprWithAlias { expr, alias },
11193-
None => SelectItem::UnnamedExpr(expr),
11194-
})
11184+
Expr::BinaryOp {
11185+
left,
11186+
op: BinaryOperator::Eq,
11187+
right,
11188+
} if self.dialect.supports_eq_alias_assigment()
11189+
&& matches!(left.as_ref(), Expr::Identifier(_)) =>
11190+
{
11191+
let Expr::Identifier(alias) = *left else {
11192+
return parser_err!(
11193+
"BUG: expected identifier expression as alias",
11194+
self.peek_token().location
11195+
);
11196+
};
11197+
Ok(SelectItem::ExprWithAlias {
11198+
expr: *right,
11199+
alias,
11200+
})
1119511201
}
11202+
expr => self
11203+
.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)
11204+
.map(|alias| match alias {
11205+
Some(alias) => SelectItem::ExprWithAlias { expr, alias },
11206+
None => SelectItem::UnnamedExpr(expr),
11207+
}),
1119611208
}
1119711209
}
1119811210

@@ -12202,28 +12214,6 @@ impl<'a> Parser<'a> {
1220212214
}
1220312215
false
1220412216
}
12205-
12206-
/// Parse a [`SelectItem`] based on an [MsSql] syntax that uses the equal sign
12207-
/// to denote an alias, for example: SELECT col_alias = col FROM tbl
12208-
/// [MsSql]: <https://learn.microsoft.com/en-us/sql/t-sql/queries/select-examples-transact-sql?view=sql-server-ver16#b-use-select-with-column-headings-and-calculations>
12209-
fn maybe_unpack_alias_assignment(expr: &Expr) -> Option<SelectItem> {
12210-
if let Expr::BinaryOp {
12211-
left,
12212-
op: BinaryOperator::Eq,
12213-
right,
12214-
..
12215-
} = expr
12216-
{
12217-
if let Expr::Identifier(ref alias) = **left {
12218-
return Some(SelectItem::ExprWithAlias {
12219-
expr: *right.clone(),
12220-
alias: alias.clone(),
12221-
});
12222-
}
12223-
}
12224-
12225-
None
12226-
}
1222712217
}
1222812218

1222912219
impl Word {

0 commit comments

Comments
 (0)