@@ -3742,7 +3742,8 @@ impl<'a> Parser<'a> {
37423742 expr: Box::new(expr),
37433743 })
37443744 } else if Token::LBracket == *tok && self.dialect.supports_partiql()
3745- || (dialect_of!(self is SnowflakeDialect | GenericDialect) && Token::Colon == *tok)
3745+ || (dialect_of!(self is SnowflakeDialect | GenericDialect | DatabricksDialect)
3746+ && Token::Colon == *tok)
37463747 {
37473748 self.prev_token();
37483749 self.parse_json_access(expr)
@@ -3889,21 +3890,26 @@ impl<'a> Parser<'a> {
38893890 })
38903891 }
38913892
3893+ // Parser is either looking at a : or a bracket expression.
38923894 fn parse_json_path(&mut self) -> Result<JsonPath, ParserError> {
38933895 let mut path = Vec::new();
3896+ let mut has_colon = false;
38943897 loop {
38953898 match self.next_token().token {
38963899 Token::Colon if path.is_empty() => {
3897- path.push(self.parse_json_path_object_key()?);
3900+ has_colon = true;
3901+ if *self.peek_token_ref() == Token::LBracket {
3902+ path.push(self.parse_json_path_bracket_element()?);
3903+ } else {
3904+ path.push(self.parse_json_path_object_key()?);
3905+ }
38983906 }
38993907 Token::Period if !path.is_empty() => {
39003908 path.push(self.parse_json_path_object_key()?);
39013909 }
39023910 Token::LBracket => {
3903- let key = self.parse_expr()?;
3904- self.expect_token(&Token::RBracket)?;
3905-
3906- path.push(JsonPathElem::Bracket { key });
3911+ self.prev_token();
3912+ path.push(self.parse_json_path_bracket_element()?);
39073913 }
39083914 _ => {
39093915 self.prev_token();
@@ -3913,7 +3919,23 @@ impl<'a> Parser<'a> {
39133919 }
39143920
39153921 debug_assert!(!path.is_empty());
3916- Ok(JsonPath { path })
3922+ Ok(JsonPath { has_colon, path })
3923+ }
3924+
3925+ /// Parses a single bracketed element in a JSON path expression, including both brackets.
3926+ fn parse_json_path_bracket_element(&mut self) -> Result<JsonPathElem, ParserError> {
3927+ self.expect_token(&Token::LBracket)?;
3928+ let elem = if *self.peek_token_ref() == Token::Mul
3929+ && self.dialect.supports_semi_structured_array_all_elements()
3930+ {
3931+ self.expect_token(&Token::Mul)?;
3932+ JsonPathElem::AllElements
3933+ } else {
3934+ let key = self.parse_expr()?;
3935+ JsonPathElem::Bracket { key }
3936+ };
3937+ self.expect_token(&Token::RBracket)?;
3938+ Ok(elem)
39173939 }
39183940
39193941 /// Parses the parens following the `[ NOT ] IN` operator.
@@ -3930,25 +3952,34 @@ impl<'a> Parser<'a> {
39303952 negated,
39313953 });
39323954 }
3933- self.expect_token(&Token::LParen)?;
3934- let in_op = match self.maybe_parse(|p| p.parse_query())? {
3935- Some(subquery) => Expr::InSubquery {
3936- expr: Box::new(expr),
3937- subquery,
3938- negated,
3939- },
3940- None => Expr::InList {
3941- expr: Box::new(expr),
3942- list: if self.dialect.supports_in_empty_list() {
3943- self.parse_comma_separated0(Parser::parse_expr, Token::RParen)?
3944- } else {
3945- self.parse_comma_separated(Parser::parse_expr)?
3955+ if self.consume_token(&Token::LParen) {
3956+ let in_op = match self.maybe_parse(|p| p.parse_query())? {
3957+ Some(subquery) => Expr::InSubquery {
3958+ expr: Box::new(expr),
3959+ subquery,
3960+ negated,
3961+ },
3962+ None => Expr::InList {
3963+ expr: Box::new(expr),
3964+ list: if self.dialect.supports_in_empty_list() {
3965+ self.parse_comma_separated0(Parser::parse_expr, Token::RParen)?
3966+ } else {
3967+ self.parse_comma_separated(Parser::parse_expr)?
3968+ },
3969+ negated,
39463970 },
3971+ };
3972+ self.expect_token(&Token::RParen)?;
3973+ Ok(in_op)
3974+ } else {
3975+ // parse an expr
3976+ let in_expr = self.parse_expr()?;
3977+ Ok(Expr::InExpr {
3978+ expr: Box::new(expr),
3979+ in_expr: Box::new(in_expr),
39473980 negated,
3948- },
3949- };
3950- self.expect_token(&Token::RParen)?;
3951- Ok(in_op)
3981+ })
3982+ }
39523983 }
39533984
39543985 /// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was already consumed.
@@ -14235,7 +14266,8 @@ impl<'a> Parser<'a> {
1423514266 | TableFactor::Unpivot { alias, .. }
1423614267 | TableFactor::MatchRecognize { alias, .. }
1423714268 | TableFactor::SemanticView { alias, .. }
14238- | TableFactor::NestedJoin { alias, .. } => {
14269+ | TableFactor::NestedJoin { alias, .. }
14270+ | TableFactor::PassThroughQuery { alias, .. } => {
1423914271 // but not `FROM (mytable AS alias1) AS alias2`.
1424014272 if let Some(inner_alias) = alias {
1424114273 return Err(ParserError::ParserError(format!(
0 commit comments