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,75 @@ 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.c 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![
371+ JsonPathElem :: Dot {
372+ key: "b" . to_owned( ) ,
373+ quoted: false
374+ } ,
375+ JsonPathElem :: Dot {
376+ key: "c" . to_owned( ) ,
377+ quoted: false
378+ }
379+ ]
380+ } ,
381+ } ) ,
382+ select. projection[ 0 ]
383+ ) ;
384+
385+ // brackets
386+ let sql = "SELECT a:b['c'][0] FROM t" ;
387+ let select = databricks ( ) . verified_only_select ( sql) ;
388+ assert_eq ! (
389+ SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
390+ value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
391+ path: JsonPath {
392+ path: vec![
393+ JsonPathElem :: Dot {
394+ key: "b" . to_owned( ) ,
395+ quoted: false
396+ } ,
397+ JsonPathElem :: Bracket {
398+ key: Expr :: value( Value :: SingleQuotedString ( "c" . to_owned( ) ) )
399+ } ,
400+ JsonPathElem :: Bracket {
401+ key: Expr :: value( number( "0" ) )
402+ }
403+ ]
404+ } ,
405+ } ) ,
406+ select. projection[ 0 ]
407+ ) ;
408+
409+ // asterisk for arrays
410+ let sql = "SELECT a:b[*].c FROM t" ;
411+ let select = databricks ( ) . verified_only_select ( sql) ;
412+ assert_eq ! (
413+ SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
414+ value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
415+ path: JsonPath {
416+ path: vec![
417+ JsonPathElem :: Dot {
418+ key: "b" . to_owned( ) ,
419+ quoted: false
420+ } ,
421+ JsonPathElem :: AllElements ,
422+ JsonPathElem :: Dot {
423+ key: "c" . to_owned( ) ,
424+ quoted: false
425+ }
426+ ]
427+ } ,
428+ } ) ,
429+ select. projection[ 0 ]
430+ ) ;
431+ }
You can’t perform that action at this time.
0 commit comments