File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -357,3 +357,46 @@ fn data_type_timestamp_ntz() {
357357 s => panic ! ( "Unexpected statement: {:?}" , s) ,
358358 }
359359}
360+
361+ #[ test]
362+ fn parse_semi_structured_data_traversal ( ) {
363+ // basic case
364+ let sql = "SELECT a:b FROM t" ;
365+ let select = databricks ( ) . verified_only_select ( sql) ;
366+ assert_eq ! (
367+ SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
368+ value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
369+ path: JsonPath {
370+ path: vec![ JsonPathElem :: Dot {
371+ key: "b" . to_owned( ) ,
372+ quoted: false
373+ } ]
374+ } ,
375+ } ) ,
376+ select. projection[ 0 ]
377+ ) ;
378+
379+ // brackets
380+ let sql = "SELECT a:b['c'][0] FROM t" ;
381+ let select = databricks ( ) . verified_only_select ( sql) ;
382+ assert_eq ! (
383+ SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
384+ value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
385+ path: JsonPath {
386+ path: vec![
387+ JsonPathElem :: Dot {
388+ key: "b" . to_owned( ) ,
389+ quoted: false
390+ } ,
391+ JsonPathElem :: Bracket {
392+ key: Expr :: value( Value :: SingleQuotedString ( "c" . to_owned( ) ) )
393+ } ,
394+ JsonPathElem :: Bracket {
395+ key: Expr :: value( number( "0" ) )
396+ }
397+ ]
398+ } ,
399+ } ) ,
400+ select. projection[ 0 ]
401+ ) ;
402+ }
You can’t perform that action at this time.
0 commit comments