@@ -1265,37 +1265,8 @@ fn parse_lateral_flatten() {
12651265// https://docs.snowflake.com/en/user-guide/querying-semistructured
12661266#[ test]
12671267fn parse_semi_structured_data_traversal ( ) {
1268- // most basic case
1269- let sql = "SELECT a:b FROM t" ;
1270- let select = snowflake ( ) . verified_only_select ( sql) ;
1271- assert_eq ! (
1272- SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
1273- value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
1274- path: JsonPath {
1275- path: vec![ JsonPathElem :: Dot {
1276- key: "b" . to_owned( ) ,
1277- quoted: false
1278- } ]
1279- } ,
1280- } ) ,
1281- select. projection[ 0 ]
1282- ) ;
1283-
1284- // identifier can be quoted
1285- let sql = r#"SELECT a:"my long object key name" FROM t"# ;
1286- let select = snowflake ( ) . verified_only_select ( sql) ;
1287- assert_eq ! (
1288- SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
1289- value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
1290- path: JsonPath {
1291- path: vec![ JsonPathElem :: Dot {
1292- key: "my long object key name" . to_owned( ) ,
1293- quoted: true
1294- } ]
1295- } ,
1296- } ) ,
1297- select. projection[ 0 ]
1298- ) ;
1268+ // see `tests/sqlparser_common.rs` -> `parse_semi_structured_data_traversal` for more test
1269+ // cases. This test only has Snowflake-specific syntax like array access.
12991270
13001271 // expressions are allowed in bracket notation
13011272 let sql = r#"SELECT a[2 + 2] FROM t"# ;
@@ -1316,88 +1287,6 @@ fn parse_semi_structured_data_traversal() {
13161287 select. projection[ 0 ]
13171288 ) ;
13181289
1319- snowflake ( ) . verified_stmt ( "SELECT a:b::INT FROM t" ) ;
1320-
1321- // unquoted keywords are permitted in the object key
1322- let sql = "SELECT a:select, a:from FROM t" ;
1323- let select = snowflake ( ) . verified_only_select ( sql) ;
1324- assert_eq ! (
1325- vec![
1326- SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
1327- value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
1328- path: JsonPath {
1329- path: vec![ JsonPathElem :: Dot {
1330- key: "select" . to_owned( ) ,
1331- quoted: false
1332- } ]
1333- } ,
1334- } ) ,
1335- SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
1336- value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
1337- path: JsonPath {
1338- path: vec![ JsonPathElem :: Dot {
1339- key: "from" . to_owned( ) ,
1340- quoted: false
1341- } ]
1342- } ,
1343- } )
1344- ] ,
1345- select. projection
1346- ) ;
1347-
1348- // multiple levels can be traversed
1349- // https://docs.snowflake.com/en/user-guide/querying-semistructured#dot-notation
1350- let sql = r#"SELECT a:foo."bar".baz"# ;
1351- let select = snowflake ( ) . verified_only_select ( sql) ;
1352- assert_eq ! (
1353- vec![ SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
1354- value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
1355- path: JsonPath {
1356- path: vec![
1357- JsonPathElem :: Dot {
1358- key: "foo" . to_owned( ) ,
1359- quoted: false ,
1360- } ,
1361- JsonPathElem :: Dot {
1362- key: "bar" . to_owned( ) ,
1363- quoted: true ,
1364- } ,
1365- JsonPathElem :: Dot {
1366- key: "baz" . to_owned( ) ,
1367- quoted: false ,
1368- }
1369- ]
1370- } ,
1371- } ) ] ,
1372- select. projection
1373- ) ;
1374-
1375- // dot and bracket notation can be mixed (starting with : case)
1376- // https://docs.snowflake.com/en/user-guide/querying-semistructured#dot-notation
1377- let sql = r#"SELECT a:foo[0].bar"# ;
1378- let select = snowflake ( ) . verified_only_select ( sql) ;
1379- assert_eq ! (
1380- vec![ SelectItem :: UnnamedExpr ( Expr :: JsonAccess {
1381- value: Box :: new( Expr :: Identifier ( Ident :: new( "a" ) ) ) ,
1382- path: JsonPath {
1383- path: vec![
1384- JsonPathElem :: Dot {
1385- key: "foo" . to_owned( ) ,
1386- quoted: false ,
1387- } ,
1388- JsonPathElem :: Bracket {
1389- key: Expr :: value( number( "0" ) ) ,
1390- } ,
1391- JsonPathElem :: Dot {
1392- key: "bar" . to_owned( ) ,
1393- quoted: false ,
1394- }
1395- ]
1396- } ,
1397- } ) ] ,
1398- select. projection
1399- ) ;
1400-
14011290 // dot and bracket notation can be mixed (starting with bracket case)
14021291 // https://docs.snowflake.com/en/user-guide/querying-semistructured#dot-notation
14031292 let sql = r#"SELECT a[0].foo.bar"# ;
0 commit comments