mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 06:18:17 +00:00
Use named fields in ExpressionWithAlias instead of a tuple
(This produces more natural JSON representation when serializing AST with serde.)
This commit is contained in:
parent
4a5dc8dd4b
commit
085e8a6b04
3 changed files with 7 additions and 7 deletions
|
@ -157,7 +157,7 @@ pub enum SQLSelectItem {
|
|||
/// Any expression, not followed by `[ AS ] alias`
|
||||
UnnamedExpression(ASTNode),
|
||||
/// An expression, followed by `[ AS ] alias`
|
||||
ExpressionWithAlias(ASTNode, SQLIdent),
|
||||
ExpressionWithAlias { expr: ASTNode, alias: SQLIdent },
|
||||
/// `alias.*` or even `schema.table.*`
|
||||
QualifiedWildcard(SQLObjectName),
|
||||
/// An unqualified `*`
|
||||
|
@ -168,7 +168,7 @@ impl ToString for SQLSelectItem {
|
|||
fn to_string(&self) -> String {
|
||||
match &self {
|
||||
SQLSelectItem::UnnamedExpression(expr) => expr.to_string(),
|
||||
SQLSelectItem::ExpressionWithAlias(expr, alias) => {
|
||||
SQLSelectItem::ExpressionWithAlias { expr, alias } => {
|
||||
format!("{} AS {}", expr.to_string(), alias)
|
||||
}
|
||||
SQLSelectItem::QualifiedWildcard(prefix) => format!("{}.*", prefix.to_string()),
|
||||
|
|
|
@ -1660,7 +1660,7 @@ impl Parser {
|
|||
if let Some(alias) =
|
||||
self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)?
|
||||
{
|
||||
projections.push(SQLSelectItem::ExpressionWithAlias(expr, alias));
|
||||
projections.push(SQLSelectItem::ExpressionWithAlias { expr, alias });
|
||||
} else {
|
||||
projections.push(SQLSelectItem::UnnamedExpression(expr));
|
||||
}
|
||||
|
|
|
@ -95,12 +95,12 @@ fn parse_select_wildcard() {
|
|||
fn parse_column_aliases() {
|
||||
let sql = "SELECT a.col + 1 AS newname FROM foo AS a";
|
||||
let select = verified_only_select(sql);
|
||||
if let SQLSelectItem::ExpressionWithAlias(
|
||||
ASTNode::SQLBinaryExpr {
|
||||
if let SQLSelectItem::ExpressionWithAlias {
|
||||
expr: ASTNode::SQLBinaryExpr {
|
||||
ref op, ref right, ..
|
||||
},
|
||||
ref alias,
|
||||
) = only(&select.projection)
|
||||
} = only(&select.projection)
|
||||
{
|
||||
assert_eq!(&SQLOperator::Plus, op);
|
||||
assert_eq!(&ASTNode::SQLValue(Value::Long(1)), right.as_ref());
|
||||
|
@ -643,7 +643,7 @@ fn parse_delimited_identifiers() {
|
|||
expr_from_projection(&select.projection[1]),
|
||||
);
|
||||
match &select.projection[2] {
|
||||
&SQLSelectItem::ExpressionWithAlias(ref expr, ref alias) => {
|
||||
SQLSelectItem::ExpressionWithAlias { expr, alias } => {
|
||||
assert_eq!(&ASTNode::SQLIdentifier(r#""simple id""#.to_string()), expr);
|
||||
assert_eq!(r#""column alias""#, alias);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue