Make TypedString preserve quote style (#1679)

This commit is contained in:
Paul Grau 2025-01-31 08:04:41 +02:00 committed by GitHub
parent aeaafbe6e4
commit 447142c6d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 132 additions and 55 deletions

View file

@ -5409,7 +5409,7 @@ fn parse_literal_date() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::Date,
value: "1999-01-01".into(),
value: Value::SingleQuotedString("1999-01-01".into()),
},
expr_from_projection(only(&select.projection)),
);
@ -5422,7 +5422,7 @@ fn parse_literal_time() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::Time(None, TimezoneInfo::None),
value: "01:23:34".into(),
value: Value::SingleQuotedString("01:23:34".into()),
},
expr_from_projection(only(&select.projection)),
);
@ -5435,7 +5435,7 @@ fn parse_literal_datetime() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::Datetime(None),
value: "1999-01-01 01:23:34.45".into(),
value: Value::SingleQuotedString("1999-01-01 01:23:34.45".into()),
},
expr_from_projection(only(&select.projection)),
);
@ -5448,7 +5448,7 @@ fn parse_literal_timestamp_without_time_zone() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::Timestamp(None, TimezoneInfo::None),
value: "1999-01-01 01:23:34".into(),
value: Value::SingleQuotedString("1999-01-01 01:23:34".into()),
},
expr_from_projection(only(&select.projection)),
);
@ -5463,7 +5463,7 @@ fn parse_literal_timestamp_with_time_zone() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::Timestamp(None, TimezoneInfo::Tz),
value: "1999-01-01 01:23:34Z".into(),
value: Value::SingleQuotedString("1999-01-01 01:23:34Z".into()),
},
expr_from_projection(only(&select.projection)),
);
@ -6015,7 +6015,8 @@ fn parse_json_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::JSON,
value: r#"{
value: Value::SingleQuotedString(
r#"{
"id": 10,
"type": "fruit",
"name": "apple",
@ -6035,12 +6036,30 @@ fn parse_json_keyword() {
]
}
}"#
.into()
.to_string()
)
},
expr_from_projection(only(&select.projection)),
);
}
#[test]
fn parse_typed_strings() {
let expr = verified_expr(r#"JSON '{"foo":"bar"}'"#);
assert_eq!(
Expr::TypedString {
data_type: DataType::JSON,
value: Value::SingleQuotedString(r#"{"foo":"bar"}"#.into())
},
expr
);
if let Expr::TypedString { data_type, value } = expr {
assert_eq!(DataType::JSON, data_type);
assert_eq!(r#"{"foo":"bar"}"#, value.into_string().unwrap());
}
}
#[test]
fn parse_bignumeric_keyword() {
let sql = r#"SELECT BIGNUMERIC '0'"#;
@ -6048,7 +6067,7 @@ fn parse_bignumeric_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::BigNumeric(ExactNumberInfo::None),
value: r#"0"#.into()
value: Value::SingleQuotedString(r#"0"#.into())
},
expr_from_projection(only(&select.projection)),
);
@ -6059,7 +6078,7 @@ fn parse_bignumeric_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::BigNumeric(ExactNumberInfo::None),
value: r#"123456"#.into()
value: Value::SingleQuotedString(r#"123456"#.into())
},
expr_from_projection(only(&select.projection)),
);
@ -6070,7 +6089,7 @@ fn parse_bignumeric_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::BigNumeric(ExactNumberInfo::None),
value: r#"-3.14"#.into()
value: Value::SingleQuotedString(r#"-3.14"#.into())
},
expr_from_projection(only(&select.projection)),
);
@ -6081,7 +6100,7 @@ fn parse_bignumeric_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::BigNumeric(ExactNumberInfo::None),
value: r#"-0.54321"#.into()
value: Value::SingleQuotedString(r#"-0.54321"#.into())
},
expr_from_projection(only(&select.projection)),
);
@ -6092,7 +6111,7 @@ fn parse_bignumeric_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::BigNumeric(ExactNumberInfo::None),
value: r#"1.23456e05"#.into()
value: Value::SingleQuotedString(r#"1.23456e05"#.into())
},
expr_from_projection(only(&select.projection)),
);
@ -6103,7 +6122,7 @@ fn parse_bignumeric_keyword() {
assert_eq!(
&Expr::TypedString {
data_type: DataType::BigNumeric(ExactNumberInfo::None),
value: r#"-9.876e-3"#.into()
value: Value::SingleQuotedString(r#"-9.876e-3"#.into())
},
expr_from_projection(only(&select.projection)),
);