Skip to content

Commit bd573b2

Browse files
committed
add tests for similar looking snowflake syntax
1 parent b9ce75a commit bd573b2

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/ast/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ pub enum Expr {
678678
},
679679
/// Access a map-like object by field (e.g. `column['field']` or `column[4]`
680680
/// Note that depending on the dialect, struct like accesses may be
681-
/// parsed as [`ArrayIndex`](Self::ArrayIndex) or [`MapAccess`](Self::MapAccess)
681+
/// parsed as [`Subscript`](Self::Subscript) or [`MapAccess`](Self::MapAccess)
682682
/// <https://clickhouse.com/docs/en/sql-reference/data-types/map/>
683683
MapAccess {
684684
column: Box<Expr>,

tests/sqlparser_postgres.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ fn parse_array_subscript() {
20382038
assert_eq!(expect, *subscript);
20392039
}
20402040

2041-
// pg_and_generic().verified_expr("schedule[:2][2:]");
2041+
pg_and_generic().verified_expr("schedule[:2][2:]");
20422042
}
20432043

20442044
#[test]

tests/sqlparser_snowflake.rs

+30
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,36 @@ fn parse_semi_structured_data_traversal() {
344344
})],
345345
select.projection
346346
);
347+
348+
// a json access used as a key to another json access
349+
assert_eq!(
350+
snowflake().verified_expr("a[b:c]"),
351+
Expr::JsonAccess {
352+
value: Box::new(Expr::Identifier(Ident::new("a"))),
353+
path: JsonPath {
354+
path: vec![JsonPathElem::Bracket {
355+
key: Expr::JsonAccess {
356+
value: Box::new(Expr::Identifier(Ident::new("b"))),
357+
path: JsonPath {
358+
path: vec![JsonPathElem::Dot {
359+
key: "c".to_owned(),
360+
quoted: false
361+
}]
362+
}
363+
}
364+
}]
365+
}
366+
}
367+
);
368+
369+
// unquoted object keys cannot start with a digit
370+
assert_eq!(
371+
snowflake()
372+
.parse_sql_statements("SELECT a:42")
373+
.unwrap_err()
374+
.to_string(),
375+
"sql parser error: Expected variant object key name, found: 42"
376+
);
347377
}
348378

349379
#[test]

0 commit comments

Comments
 (0)