File tree Expand file tree Collapse file tree 5 files changed +28
-3
lines changed Expand file tree Collapse file tree 5 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -519,6 +519,10 @@ pub enum JsonPathElem {
519
519
///
520
520
/// See <https://docs.snowflake.com/en/user-guide/querying-semistructured#bracket-notation>.
521
521
Bracket { key : Expr } ,
522
+ /// Accesses all elements in the given (generally array) element. Used for constructs like `foo:bar[*].baz`.
523
+ ///
524
+ /// See <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-json-path-expression#extract-values-from-arrays>
525
+ AllElements ,
522
526
}
523
527
524
528
/// A JSON path.
@@ -552,6 +556,9 @@ impl fmt::Display for JsonPath {
552
556
JsonPathElem :: Bracket { key } => {
553
557
write ! ( f, "[{key}]" ) ?;
554
558
}
559
+ JsonPathElem :: AllElements => {
560
+ write ! ( f, "[*]" ) ?;
561
+ }
555
562
}
556
563
}
557
564
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -1725,11 +1725,13 @@ impl Spanned for JsonPath {
1725
1725
///
1726
1726
/// Missing spans:
1727
1727
/// - [JsonPathElem::Dot]
1728
+ /// - [JsonPathElem::AllElements]
1728
1729
impl Spanned for JsonPathElem {
1729
1730
fn span ( & self ) -> Span {
1730
1731
match self {
1731
1732
JsonPathElem :: Dot { .. } => Span :: empty ( ) ,
1732
1733
JsonPathElem :: Bracket { key } => key. span ( ) ,
1734
+ JsonPathElem :: AllElements => Span :: empty ( ) ,
1733
1735
}
1734
1736
}
1735
1737
}
Original file line number Diff line number Diff line change @@ -49,6 +49,10 @@ impl Dialect for DatabricksDialect {
49
49
}
50
50
}
51
51
52
+ fn supports_semi_structured_array_all_elements ( & self ) -> bool {
53
+ true
54
+ }
55
+
52
56
fn supports_filter_during_aggregation ( & self ) -> bool {
53
57
true
54
58
}
Original file line number Diff line number Diff line change @@ -876,6 +876,11 @@ pub trait Dialect: Debug + Any {
876
876
false
877
877
}
878
878
879
+ /// Returns true if the dialect supports writing `[*]` to select all elements in a JSON array.
880
+ fn supports_semi_structured_array_all_elements ( & self ) -> bool {
881
+ false
882
+ }
883
+
879
884
/// Returns true if the specified keyword is reserved and cannot be
880
885
/// used as an identifier without special handling like quoting.
881
886
fn is_reserved_for_identifier ( & self , kw : Keyword ) -> bool {
Original file line number Diff line number Diff line change @@ -3726,10 +3726,17 @@ impl<'a> Parser<'a> {
3726
3726
path.push(self.parse_json_path_object_key()?);
3727
3727
}
3728
3728
Token::LBracket => {
3729
- let key = self.parse_expr()?;
3730
- self.expect_token(&Token::RBracket)?;
3729
+ if self.peek_token_ref().token == Token::Mul
3730
+ && self.dialect.supports_semi_structured_array_all_elements()
3731
+ {
3732
+ self.expect_token(&Token::Mul)?;
3733
+ path.push(JsonPathElem::AllElements);
3734
+ } else {
3735
+ let key = self.parse_expr()?;
3736
+ path.push(JsonPathElem::Bracket { key });
3737
+ }
3731
3738
3732
- path.push(JsonPathElem::Bracket { key }) ;
3739
+ self.expect_token(&Token::RBracket)? ;
3733
3740
}
3734
3741
_ => {
3735
3742
self.prev_token();
You can’t perform that action at this time.
0 commit comments