@@ -314,4 +314,91 @@ fn test_drop_secret_simple() {
314314 ,
315315 stmt
316316 ) ;
317- }
317+ }
318+
319+ #[ test]
320+ fn test_duckdb_struct_literal ( ) {
321+ //struct literal syntax https://duckdb.org/docs/sql/data_types/struct#creating-structs
322+ //syntax: {'field_name': expr1[, ... ]}
323+ 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}}" ;
324+ let select = duckdb_and_generic ( ) . verified_only_select ( sql) ;
325+ assert_eq ! ( 6 , select. projection. len( ) ) ;
326+ assert_eq ! (
327+ & Expr :: Dictionary ( vec![
328+ DictionaryField {
329+ key: Ident :: with_quote( '\'' , "a" ) ,
330+ value: Box :: new( Expr :: Value ( number( "1" ) ) ) ,
331+ } ,
332+ DictionaryField {
333+ key: Ident :: with_quote( '\'' , "b" ) ,
334+ value: Box :: new( Expr :: Value ( number( "2" ) ) ) ,
335+ } ,
336+ DictionaryField {
337+ key: Ident :: with_quote( '\'' , "c" ) ,
338+ value: Box :: new( Expr :: Value ( number( "3" ) ) ) ,
339+ } ,
340+ ] , ) ,
341+ expr_from_projection( & select. projection[ 0 ] )
342+ ) ;
343+
344+ assert_eq ! (
345+ & Expr :: Array ( Array {
346+ elem: vec![ Expr :: Dictionary ( vec![ DictionaryField {
347+ key: Ident :: with_quote( '\'' , "a" ) ,
348+ value: Box :: new( Expr :: Value ( Value :: SingleQuotedString ( "abc" . to_string( ) ) ) ) ,
349+ } , ] , ) ] ,
350+ named: false
351+ } ) ,
352+ expr_from_projection( & select. projection[ 1 ] )
353+ ) ;
354+ assert_eq ! (
355+ & Expr :: Dictionary ( vec![
356+ DictionaryField {
357+ key: Ident :: with_quote( '\'' , "a" ) ,
358+ value: Box :: new( Expr :: Value ( number( "1" ) ) ) ,
359+ } ,
360+ DictionaryField {
361+ key: Ident :: with_quote( '\'' , "b" ) ,
362+ value: Box :: new( Expr :: Array ( Array {
363+ elem: vec![ Expr :: CompoundIdentifier ( vec![
364+ Ident :: from( "t" ) ,
365+ Ident :: from( "str_col" )
366+ ] ) ] ,
367+ named: false
368+ } ) ) ,
369+ } ,
370+ ] , ) ,
371+ expr_from_projection( & select. projection[ 2 ] )
372+ ) ;
373+ assert_eq ! (
374+ & Expr :: Dictionary ( vec![
375+ DictionaryField {
376+ key: Ident :: with_quote( '\'' , "a" ) ,
377+ value: Expr :: Value ( number( "1" ) ) . into( ) ,
378+ } ,
379+ DictionaryField {
380+ key: Ident :: with_quote( '\'' , "b" ) ,
381+ value: Expr :: Value ( Value :: SingleQuotedString ( "abc" . to_string( ) ) ) . into( ) ,
382+ } ,
383+ ] , ) ,
384+ expr_from_projection( & select. projection[ 3 ] )
385+ ) ;
386+ assert_eq ! (
387+ & Expr :: Dictionary ( vec![ DictionaryField {
388+ key: Ident :: with_quote( '\'' , "abc" ) ,
389+ value: Expr :: Identifier ( Ident :: from( "str_col" ) ) . into( ) ,
390+ } ] , ) ,
391+ expr_from_projection( & select. projection[ 4 ] )
392+ ) ;
393+ assert_eq ! (
394+ & Expr :: Dictionary ( vec![ DictionaryField {
395+ key: Ident :: with_quote( '\'' , "a" ) ,
396+ value: Expr :: Dictionary ( vec![ DictionaryField {
397+ key: Ident :: with_quote( '\'' , "aa" ) ,
398+ value: Expr :: Value ( number( "1" ) ) . into( ) ,
399+ } ] , )
400+ . into( ) ,
401+ } ] , ) ,
402+ expr_from_projection( & select. projection[ 5 ] )
403+ ) ;
404+ }
0 commit comments