mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 23:49:10 +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`
|
/// Any expression, not followed by `[ AS ] alias`
|
||||||
UnnamedExpression(ASTNode),
|
UnnamedExpression(ASTNode),
|
||||||
/// An expression, followed by `[ AS ] alias`
|
/// An expression, followed by `[ AS ] alias`
|
||||||
ExpressionWithAlias(ASTNode, SQLIdent),
|
ExpressionWithAlias { expr: ASTNode, alias: SQLIdent },
|
||||||
/// `alias.*` or even `schema.table.*`
|
/// `alias.*` or even `schema.table.*`
|
||||||
QualifiedWildcard(SQLObjectName),
|
QualifiedWildcard(SQLObjectName),
|
||||||
/// An unqualified `*`
|
/// An unqualified `*`
|
||||||
|
@ -168,7 +168,7 @@ impl ToString for SQLSelectItem {
|
||||||
fn to_string(&self) -> String {
|
fn to_string(&self) -> String {
|
||||||
match &self {
|
match &self {
|
||||||
SQLSelectItem::UnnamedExpression(expr) => expr.to_string(),
|
SQLSelectItem::UnnamedExpression(expr) => expr.to_string(),
|
||||||
SQLSelectItem::ExpressionWithAlias(expr, alias) => {
|
SQLSelectItem::ExpressionWithAlias { expr, alias } => {
|
||||||
format!("{} AS {}", expr.to_string(), alias)
|
format!("{} AS {}", expr.to_string(), alias)
|
||||||
}
|
}
|
||||||
SQLSelectItem::QualifiedWildcard(prefix) => format!("{}.*", prefix.to_string()),
|
SQLSelectItem::QualifiedWildcard(prefix) => format!("{}.*", prefix.to_string()),
|
||||||
|
|
|
@ -1660,7 +1660,7 @@ impl Parser {
|
||||||
if let Some(alias) =
|
if let Some(alias) =
|
||||||
self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)?
|
self.parse_optional_alias(keywords::RESERVED_FOR_COLUMN_ALIAS)?
|
||||||
{
|
{
|
||||||
projections.push(SQLSelectItem::ExpressionWithAlias(expr, alias));
|
projections.push(SQLSelectItem::ExpressionWithAlias { expr, alias });
|
||||||
} else {
|
} else {
|
||||||
projections.push(SQLSelectItem::UnnamedExpression(expr));
|
projections.push(SQLSelectItem::UnnamedExpression(expr));
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,12 +95,12 @@ fn parse_select_wildcard() {
|
||||||
fn parse_column_aliases() {
|
fn parse_column_aliases() {
|
||||||
let sql = "SELECT a.col + 1 AS newname FROM foo AS a";
|
let sql = "SELECT a.col + 1 AS newname FROM foo AS a";
|
||||||
let select = verified_only_select(sql);
|
let select = verified_only_select(sql);
|
||||||
if let SQLSelectItem::ExpressionWithAlias(
|
if let SQLSelectItem::ExpressionWithAlias {
|
||||||
ASTNode::SQLBinaryExpr {
|
expr: ASTNode::SQLBinaryExpr {
|
||||||
ref op, ref right, ..
|
ref op, ref right, ..
|
||||||
},
|
},
|
||||||
ref alias,
|
ref alias,
|
||||||
) = only(&select.projection)
|
} = only(&select.projection)
|
||||||
{
|
{
|
||||||
assert_eq!(&SQLOperator::Plus, op);
|
assert_eq!(&SQLOperator::Plus, op);
|
||||||
assert_eq!(&ASTNode::SQLValue(Value::Long(1)), right.as_ref());
|
assert_eq!(&ASTNode::SQLValue(Value::Long(1)), right.as_ref());
|
||||||
|
@ -643,7 +643,7 @@ fn parse_delimited_identifiers() {
|
||||||
expr_from_projection(&select.projection[1]),
|
expr_from_projection(&select.projection[1]),
|
||||||
);
|
);
|
||||||
match &select.projection[2] {
|
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!(&ASTNode::SQLIdentifier(r#""simple id""#.to_string()), expr);
|
||||||
assert_eq!(r#""column alias""#, alias);
|
assert_eq!(r#""column alias""#, alias);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue