Skip to content

Commit

Permalink
add tests for similar looking snowflake syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhain committed May 27, 2024
1 parent b9ce75a commit bd573b2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ pub enum Expr {
},
/// Access a map-like object by field (e.g. `column['field']` or `column[4]`
/// Note that depending on the dialect, struct like accesses may be
/// parsed as [`ArrayIndex`](Self::ArrayIndex) or [`MapAccess`](Self::MapAccess)
/// parsed as [`Subscript`](Self::Subscript) or [`MapAccess`](Self::MapAccess)
/// <https://clickhouse.com/docs/en/sql-reference/data-types/map/>
MapAccess {
column: Box<Expr>,
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ fn parse_array_subscript() {
assert_eq!(expect, *subscript);
}

// pg_and_generic().verified_expr("schedule[:2][2:]");
pg_and_generic().verified_expr("schedule[:2][2:]");
}

#[test]
Expand Down
30 changes: 30 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,36 @@ fn parse_semi_structured_data_traversal() {
})],
select.projection
);

// a json access used as a key to another json access
assert_eq!(
snowflake().verified_expr("a[b:c]"),
Expr::JsonAccess {
value: Box::new(Expr::Identifier(Ident::new("a"))),
path: JsonPath {
path: vec![JsonPathElem::Bracket {
key: Expr::JsonAccess {
value: Box::new(Expr::Identifier(Ident::new("b"))),
path: JsonPath {
path: vec![JsonPathElem::Dot {
key: "c".to_owned(),
quoted: false
}]
}
}
}]
}
}
);

// unquoted object keys cannot start with a digit
assert_eq!(
snowflake()
.parse_sql_statements("SELECT a:42")
.unwrap_err()
.to_string(),
"sql parser error: Expected variant object key name, found: 42"
);
}

#[test]
Expand Down

0 comments on commit bd573b2

Please sign in to comment.