Skip to content

Commit 4be8117

Browse files
authored
Fix :start and :end json accesses on snowflake (apache#1110)
1 parent f5e2736 commit 4be8117

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/parser/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5471,7 +5471,14 @@ impl<'a> Parser<'a> {
54715471
)?,
54725472
},
54735473
// Case when Snowflake Semi-structured data like key:value
5474-
Keyword::NoKeyword | Keyword::LOCATION | Keyword::TYPE | Keyword::DATE if dialect_of!(self is SnowflakeDialect | GenericDialect) => {
5474+
Keyword::NoKeyword
5475+
| Keyword::LOCATION
5476+
| Keyword::TYPE
5477+
| Keyword::DATE
5478+
| Keyword::START
5479+
| Keyword::END
5480+
if dialect_of!(self is SnowflakeDialect | GenericDialect) =>
5481+
{
54755482
Ok(Value::UnQuotedString(w.value))
54765483
}
54775484
_ => self.expected(

tests/sqlparser_snowflake.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ fn parse_json_using_colon() {
229229
);
230230

231231
snowflake().one_statement_parses_to("SELECT a:b::int FROM t", "SELECT CAST(a:b AS INT) FROM t");
232+
233+
let sql = "SELECT a:start, a:end FROM t";
234+
let select = snowflake().verified_only_select(sql);
235+
assert_eq!(
236+
vec![
237+
SelectItem::UnnamedExpr(Expr::JsonAccess {
238+
left: Box::new(Expr::Identifier(Ident::new("a"))),
239+
operator: JsonOperator::Colon,
240+
right: Box::new(Expr::Value(Value::UnQuotedString("start".to_string()))),
241+
}),
242+
SelectItem::UnnamedExpr(Expr::JsonAccess {
243+
left: Box::new(Expr::Identifier(Ident::new("a"))),
244+
operator: JsonOperator::Colon,
245+
right: Box::new(Expr::Value(Value::UnQuotedString("end".to_string()))),
246+
})
247+
],
248+
select.projection
249+
);
232250
}
233251

234252
#[test]

0 commit comments

Comments
 (0)