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

Method expect_grant_target_specification

src/sql-parser/src/parser.rs:9626–9680  ·  view source on GitHub ↗
(
        &mut self,
        statement_type: &str,
    )

Source from the content-addressed store, hash-verified

9624 }
9625
9626 fn expect_grant_target_specification(
9627 &mut self,
9628 statement_type: &str,
9629 ) -> Result<GrantTargetSpecification<Raw>, ParserError> {
9630 if self.parse_keyword(SYSTEM) {
9631 return Ok(GrantTargetSpecification::System);
9632 }
9633
9634 let (object_type, object_spec_inner) = if self.parse_keyword(ALL) {
9635 let object_type = self.expect_grant_revoke_plural_object_type(statement_type)?;
9636 let object_spec_inner = if self.parse_keyword(IN) {
9637 if !object_type.lives_in_schema() && object_type != ObjectType::Schema {
9638 return parser_err!(
9639 self,
9640 self.peek_prev_pos(),
9641 format!("IN invalid for {object_type}S")
9642 );
9643 }
9644 match self.expect_one_of_keywords(&[DATABASE, SCHEMA])? {
9645 DATABASE => GrantTargetSpecificationInner::All(
9646 GrantTargetAllSpecification::AllDatabases {
9647 databases: self.parse_comma_separated(Parser::parse_database_name)?,
9648 },
9649 ),
9650 SCHEMA => {
9651 if object_type == ObjectType::Schema {
9652 self.prev_token();
9653 self.expected(self.peek_pos(), DATABASE, self.peek_token())?;
9654 }
9655 GrantTargetSpecificationInner::All(
9656 GrantTargetAllSpecification::AllSchemas {
9657 schemas: self.parse_comma_separated(Parser::parse_schema_name)?,
9658 },
9659 )
9660 }
9661 _ => unreachable!(),
9662 }
9663 } else {
9664 GrantTargetSpecificationInner::All(GrantTargetAllSpecification::All)
9665 };
9666 (object_type, object_spec_inner)
9667 } else {
9668 let object_type = self.expect_grant_revoke_object_type(statement_type)?;
9669 let object_spec_inner = GrantTargetSpecificationInner::Objects {
9670 names: self
9671 .parse_comma_separated(|parser| parser.parse_object_name(object_type))?,
9672 };
9673 (object_type, object_spec_inner)
9674 };
9675
9676 Ok(GrantTargetSpecification::Object {
9677 object_type,
9678 object_spec_inner,
9679 })
9680 }
9681
9682 /// Bail out if the current token is not an object type suitable for a GRANT/REVOKE, or consume
9683 /// and return it if it is.

Callers 2

parse_grant_privilegeMethod · 0.80

Calls 11

parse_keywordMethod · 0.80
lives_in_schemaMethod · 0.80
parse_comma_separatedMethod · 0.80
prev_tokenMethod · 0.80
expectedMethod · 0.80
peek_posMethod · 0.80
peek_tokenMethod · 0.80
parse_object_nameMethod · 0.80

Tested by

no test coverage detected