MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_any_all

Method parse_any_all

src/sql-parser/src/parser.rs:1554–1606  ·  view source on GitHub ↗

Parses an `ANY`, `ALL`, or `SOME` operation, starting after the `ANY`, `ALL`, or `SOME` keyword.

(
        &mut self,
        left: Expr<Raw>,
        op: Op,
        kw: Keyword,
    )

Source from the content-addressed store, hash-verified

1552 /// Parses an `ANY`, `ALL`, or `SOME` operation, starting after the `ANY`,
1553 /// `ALL`, or `SOME` keyword.
1554 fn parse_any_all(
1555 &mut self,
1556 left: Expr<Raw>,
1557 op: Op,
1558 kw: Keyword,
1559 ) -> Result<Expr<Raw>, ParserError> {
1560 self.expect_token(&Token::LParen)?;
1561
1562 let expr = match self.parse_parenthesized_fragment()? {
1563 ParenthesizedFragment::Exprs(exprs) => {
1564 if exprs.len() > 1 {
1565 return parser_err!(
1566 self,
1567 self.peek_pos(),
1568 "{kw} requires a single expression or subquery, not an expression list",
1569 );
1570 }
1571 let right = exprs.into_element();
1572 if kw == ALL {
1573 Expr::AllExpr {
1574 left: Box::new(left),
1575 op,
1576 right: Box::new(right),
1577 }
1578 } else {
1579 Expr::AnyExpr {
1580 left: Box::new(left),
1581 op,
1582 right: Box::new(right),
1583 }
1584 }
1585 }
1586 ParenthesizedFragment::Query(subquery) => {
1587 if kw == ALL {
1588 Expr::AllSubquery {
1589 left: Box::new(left),
1590 op,
1591 right: Box::new(subquery),
1592 }
1593 } else {
1594 Expr::AnySubquery {
1595 left: Box::new(left),
1596 op,
1597 right: Box::new(subquery),
1598 }
1599 }
1600 }
1601 };
1602
1603 self.expect_token(&Token::RParen)?;
1604
1605 Ok(expr)
1606 }
1607
1608 /// Parses the parens following the `[ NOT ] IN` operator
1609 fn parse_in(&mut self, expr: Expr<Raw>, negated: bool) -> Result<Expr<Raw>, ParserError> {

Callers 2

parse_infixMethod · 0.80
parse_likeMethod · 0.80

Calls 4

expect_tokenMethod · 0.80
into_elementMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected