Fix :start and :end json accesses on snowflake (#1110)

This commit is contained in:
Joey Hain 2024-01-25 11:59:33 -08:00 committed by GitHub
parent f5e27366f3
commit 4be8117af0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -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(

View file

@ -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]