mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 14:28:22 +00:00
Add support for DuckDB struct literal syntax (#1194)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
4472789171
commit
e747c9c2af
3 changed files with 158 additions and 0 deletions
|
@ -246,3 +246,90 @@ fn test_duckdb_load_extension() {
|
|||
stmt
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duckdb_struct_literal() {
|
||||
//struct literal syntax https://duckdb.org/docs/sql/data_types/struct#creating-structs
|
||||
//syntax: {'field_name': expr1[, ... ]}
|
||||
let sql = "SELECT {'a': 1, 'b': 2, 'c': 3}, [{'a': 'abc'}], {'a': 1, 'b': [t.str_col]}, {'a': 1, 'b': 'abc'}, {'abc': str_col}, {'a': {'aa': 1}}";
|
||||
let select = duckdb_and_generic().verified_only_select(sql);
|
||||
assert_eq!(6, select.projection.len());
|
||||
assert_eq!(
|
||||
&Expr::Dictionary(vec![
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "a"),
|
||||
value: Box::new(Expr::Value(number("1"))),
|
||||
},
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "b"),
|
||||
value: Box::new(Expr::Value(number("2"))),
|
||||
},
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "c"),
|
||||
value: Box::new(Expr::Value(number("3"))),
|
||||
},
|
||||
],),
|
||||
expr_from_projection(&select.projection[0])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
&Expr::Array(Array {
|
||||
elem: vec![Expr::Dictionary(vec![DictionaryField {
|
||||
key: Ident::with_quote('\'', "a"),
|
||||
value: Box::new(Expr::Value(Value::SingleQuotedString("abc".to_string()))),
|
||||
},],)],
|
||||
named: false
|
||||
}),
|
||||
expr_from_projection(&select.projection[1])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Dictionary(vec![
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "a"),
|
||||
value: Box::new(Expr::Value(number("1"))),
|
||||
},
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "b"),
|
||||
value: Box::new(Expr::Array(Array {
|
||||
elem: vec![Expr::CompoundIdentifier(vec![
|
||||
Ident::from("t"),
|
||||
Ident::from("str_col")
|
||||
])],
|
||||
named: false
|
||||
})),
|
||||
},
|
||||
],),
|
||||
expr_from_projection(&select.projection[2])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Dictionary(vec![
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "a"),
|
||||
value: Expr::Value(number("1")).into(),
|
||||
},
|
||||
DictionaryField {
|
||||
key: Ident::with_quote('\'', "b"),
|
||||
value: Expr::Value(Value::SingleQuotedString("abc".to_string())).into(),
|
||||
},
|
||||
],),
|
||||
expr_from_projection(&select.projection[3])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Dictionary(vec![DictionaryField {
|
||||
key: Ident::with_quote('\'', "abc"),
|
||||
value: Expr::Identifier(Ident::from("str_col")).into(),
|
||||
}],),
|
||||
expr_from_projection(&select.projection[4])
|
||||
);
|
||||
assert_eq!(
|
||||
&Expr::Dictionary(vec![DictionaryField {
|
||||
key: Ident::with_quote('\'', "a"),
|
||||
value: Expr::Dictionary(vec![DictionaryField {
|
||||
key: Ident::with_quote('\'', "aa"),
|
||||
value: Expr::Value(number("1")).into(),
|
||||
}],)
|
||||
.into(),
|
||||
}],),
|
||||
expr_from_projection(&select.projection[5])
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue