Store spans for Value expressions (#1738)

This commit is contained in:
Ophir LOJKINE 2025-02-25 07:33:57 +01:00 committed by GitHub
parent aab12add36
commit c335c8883b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1620 additions and 1042 deletions

View file

@ -52,11 +52,11 @@ fn parse_literal_string() {
let select = mysql().verified_only_select(sql);
assert_eq!(2, select.projection.len());
assert_eq!(
&Expr::Value(Value::SingleQuotedString("single".to_string())),
&Expr::Value((Value::SingleQuotedString("single".to_string())).with_empty_span()),
expr_from_projection(&select.projection[0])
);
assert_eq!(
&Expr::Value(Value::DoubleQuotedString("double".to_string())),
&Expr::Value((Value::DoubleQuotedString("double".to_string())).with_empty_span()),
expr_from_projection(&select.projection[1])
);
}
@ -621,7 +621,7 @@ fn parse_set_variables() {
local: true,
hivevar: false,
variables: OneOrManyWithParens::One(ObjectName::from(vec!["autocommit".into()])),
value: vec![Expr::Value(number("1"))],
value: vec![Expr::value(number("1"))],
}
);
}
@ -986,7 +986,9 @@ fn parse_create_table_both_options_and_as_query() {
assert_eq!(collation, Some("utf8mb4_0900_ai_ci".to_string()));
assert_eq!(
query.unwrap().body.as_select().unwrap().projection,
vec![SelectItem::UnnamedExpr(Expr::Value(number("1")))]
vec![SelectItem::UnnamedExpr(Expr::Value(
(number("1")).with_empty_span()
))]
);
}
_ => unreachable!(),
@ -1413,18 +1415,25 @@ fn parse_simple_insert() {
explicit_row: false,
rows: vec![
vec![
Expr::Value(Value::SingleQuotedString(
"Test Some Inserts".to_string()
)),
Expr::Value(number("1"))
Expr::Value(
(Value::SingleQuotedString("Test Some Inserts".to_string()))
.with_empty_span()
),
Expr::value(number("1"))
],
vec![
Expr::Value(Value::SingleQuotedString("Test Entry 2".to_string())),
Expr::Value(number("2"))
Expr::Value(
(Value::SingleQuotedString("Test Entry 2".to_string()))
.with_empty_span()
),
Expr::value(number("2"))
],
vec![
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
Expr::Value(number("3"))
Expr::Value(
(Value::SingleQuotedString("Test Entry 3".to_string()))
.with_empty_span()
),
Expr::value(number("3"))
]
]
})),
@ -1471,8 +1480,11 @@ fn parse_ignore_insert() {
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
Expr::Value(number("1"))
Expr::Value(
(Value::SingleQuotedString("Test Some Inserts".to_string()))
.with_empty_span()
),
Expr::value(number("1"))
]]
})),
order_by: None,
@ -1518,8 +1530,11 @@ fn parse_priority_insert() {
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
Expr::Value(number("1"))
Expr::Value(
(Value::SingleQuotedString("Test Some Inserts".to_string()))
.with_empty_span()
),
Expr::value(number("1"))
]]
})),
order_by: None,
@ -1562,8 +1577,11 @@ fn parse_priority_insert() {
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
Expr::Value(number("1"))
Expr::Value(
(Value::SingleQuotedString("Test Some Inserts".to_string()))
.with_empty_span()
),
Expr::value(number("1"))
]]
})),
order_by: None,
@ -1611,9 +1629,9 @@ fn parse_insert_as() {
with: None,
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![Expr::Value(Value::SingleQuotedString(
"2024-01-01".to_string()
))]]
rows: vec![vec![Expr::Value(
(Value::SingleQuotedString("2024-01-01".to_string())).with_empty_span()
)]]
})),
order_by: None,
limit: None,
@ -1672,8 +1690,11 @@ fn parse_insert_as() {
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![
Expr::Value(number("1")),
Expr::Value(Value::SingleQuotedString("2024-01-01".to_string()))
Expr::value(number("1")),
Expr::Value(
(Value::SingleQuotedString("2024-01-01".to_string()))
.with_empty_span()
)
]]
})),
order_by: None,
@ -1720,8 +1741,11 @@ fn parse_replace_insert() {
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
Expr::Value(number("1"))
Expr::Value(
(Value::SingleQuotedString("Test Some Inserts".to_string()))
.with_empty_span()
),
Expr::value(number("1"))
]]
})),
order_by: None,
@ -1816,16 +1840,20 @@ fn parse_insert_with_on_duplicate_update() {
body: Box::new(SetExpr::Values(Values {
explicit_row: false,
rows: vec![vec![
Expr::Value(Value::SingleQuotedString(
"accounting_manager".to_string()
)),
Expr::Value(Value::SingleQuotedString(
"Some description about the group".to_string()
)),
Expr::Value(Value::Boolean(true)),
Expr::Value(Value::Boolean(true)),
Expr::Value(Value::Boolean(true)),
Expr::Value(Value::Boolean(true)),
Expr::Value(
(Value::SingleQuotedString("accounting_manager".to_string()))
.with_empty_span()
),
Expr::Value(
(Value::SingleQuotedString(
"Some description about the group".to_string()
))
.with_empty_span()
),
Expr::Value((Value::Boolean(true)).with_empty_span()),
Expr::Value((Value::Boolean(true)).with_empty_span()),
Expr::Value((Value::Boolean(true)).with_empty_span()),
Expr::Value((Value::Boolean(true)).with_empty_span()),
]]
})),
order_by: None,
@ -1946,7 +1974,7 @@ fn parse_select_with_concatenation_of_exp_number_and_numeric_prefix_column() {
top: None,
top_before_distinct: false,
projection: vec![
SelectItem::UnnamedExpr(Expr::Value(number("123e4"))),
SelectItem::UnnamedExpr(Expr::value(number("123e4"))),
SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("123col_$@123abc")))
],
into: None,
@ -2063,7 +2091,7 @@ fn parse_update_with_joins() {
Ident::new("o"),
Ident::new("completed")
])),
value: Expr::Value(Value::Boolean(true))
value: Expr::Value((Value::Boolean(true)).with_empty_span())
}],
assignments
);
@ -2074,7 +2102,9 @@ fn parse_update_with_joins() {
Ident::new("firstname")
])),
op: BinaryOperator::Eq,
right: Box::new(Expr::Value(Value::SingleQuotedString("Peter".to_string())))
right: Box::new(Expr::Value(
(Value::SingleQuotedString("Peter".to_string())).with_empty_span()
))
}),
selection
);
@ -2114,7 +2144,7 @@ fn parse_delete_with_limit() {
let sql = "DELETE FROM customers LIMIT 100";
match mysql().verified_stmt(sql) {
Statement::Delete(Delete { limit, .. }) => {
assert_eq!(Some(Expr::Value(number("100"))), limit);
assert_eq!(Some(Expr::value(number("100"))), limit);
}
_ => unreachable!(),
}
@ -2462,8 +2492,12 @@ fn parse_substring_in_select() {
quote_style: None,
span: Span::empty(),
})),
substring_from: Some(Box::new(Expr::Value(number("0")))),
substring_for: Some(Box::new(Expr::Value(number("1")))),
substring_from: Some(Box::new(Expr::Value(
(number("0")).with_empty_span()
))),
substring_for: Some(Box::new(Expr::Value(
(number("1")).with_empty_span()
))),
special: true,
})],
into: None,
@ -2937,7 +2971,7 @@ fn parse_json_table() {
.from[0]
.relation,
TableFactor::JsonTable {
json_expr: Expr::Value(Value::SingleQuotedString("[1,2]".to_string())),
json_expr: Expr::Value((Value::SingleQuotedString("[1,2]".to_string())).with_empty_span()),
json_path: Value::SingleQuotedString("$[*]".to_string()),
columns: vec![
JsonTableColumn::Named(JsonTableNamedColumn {
@ -2975,33 +3009,33 @@ fn parse_logical_xor() {
let select = mysql_and_generic().verified_only_select(sql);
assert_eq!(
SelectItem::UnnamedExpr(Expr::BinaryOp {
left: Box::new(Expr::Value(Value::Boolean(true))),
left: Box::new(Expr::Value((Value::Boolean(true)).with_empty_span())),
op: BinaryOperator::Xor,
right: Box::new(Expr::Value(Value::Boolean(true))),
right: Box::new(Expr::Value((Value::Boolean(true)).with_empty_span())),
}),
select.projection[0]
);
assert_eq!(
SelectItem::UnnamedExpr(Expr::BinaryOp {
left: Box::new(Expr::Value(Value::Boolean(false))),
left: Box::new(Expr::Value((Value::Boolean(false)).with_empty_span())),
op: BinaryOperator::Xor,
right: Box::new(Expr::Value(Value::Boolean(false))),
right: Box::new(Expr::Value((Value::Boolean(false)).with_empty_span())),
}),
select.projection[1]
);
assert_eq!(
SelectItem::UnnamedExpr(Expr::BinaryOp {
left: Box::new(Expr::Value(Value::Boolean(true))),
left: Box::new(Expr::Value((Value::Boolean(true)).with_empty_span())),
op: BinaryOperator::Xor,
right: Box::new(Expr::Value(Value::Boolean(false))),
right: Box::new(Expr::Value((Value::Boolean(false)).with_empty_span())),
}),
select.projection[2]
);
assert_eq!(
SelectItem::UnnamedExpr(Expr::BinaryOp {
left: Box::new(Expr::Value(Value::Boolean(false))),
left: Box::new(Expr::Value((Value::Boolean(false)).with_empty_span())),
op: BinaryOperator::Xor,
right: Box::new(Expr::Value(Value::Boolean(true))),
right: Box::new(Expr::Value((Value::Boolean(true)).with_empty_span())),
}),
select.projection[3]
);
@ -3013,7 +3047,7 @@ fn parse_bitstring_literal() {
assert_eq!(
select.projection,
vec![SelectItem::UnnamedExpr(Expr::Value(
Value::SingleQuotedByteStringLiteral("111".to_string())
(Value::SingleQuotedByteStringLiteral("111".to_string())).with_empty_span()
))]
);
}