Skip to content

Commit

Permalink
Fix :start and :end json accesses on snowflake (#1110)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhain authored Jan 25, 2024
1 parent f5e2736 commit 4be8117
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5471,7 +5471,14 @@ impl<'a> Parser<'a> {
)?,
},
// Case when Snowflake Semi-structured data like key:value
Keyword::NoKeyword | Keyword::LOCATION | Keyword::TYPE | Keyword::DATE if dialect_of!(self is SnowflakeDialect | GenericDialect) => {
Keyword::NoKeyword
| Keyword::LOCATION
| Keyword::TYPE
| Keyword::DATE
| Keyword::START
| Keyword::END
if dialect_of!(self is SnowflakeDialect | GenericDialect) =>
{
Ok(Value::UnQuotedString(w.value))
}
_ => self.expected(
Expand Down
18 changes: 18 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ fn parse_json_using_colon() {
);

snowflake().one_statement_parses_to("SELECT a:b::int FROM t", "SELECT CAST(a:b AS INT) FROM t");

let sql = "SELECT a:start, a:end FROM t";
let select = snowflake().verified_only_select(sql);
assert_eq!(
vec![
SelectItem::UnnamedExpr(Expr::JsonAccess {
left: Box::new(Expr::Identifier(Ident::new("a"))),
operator: JsonOperator::Colon,
right: Box::new(Expr::Value(Value::UnQuotedString("start".to_string()))),
}),
SelectItem::UnnamedExpr(Expr::JsonAccess {
left: Box::new(Expr::Identifier(Ident::new("a"))),
operator: JsonOperator::Colon,
right: Box::new(Expr::Value(Value::UnQuotedString("end".to_string()))),
})
],
select.projection
);
}

#[test]
Expand Down

0 comments on commit 4be8117

Please sign in to comment.