@@ -5832,15 +5832,19 @@ impl<'a> Parser<'a> {
58325832 let hive_distribution = self.parse_hive_distribution()?;
58335833 let hive_formats = self.parse_hive_formats()?;
58345834
5835- let file_format = if let Some(ff) = &hive_formats.storage {
5836- match ff {
5837- HiveIOFormat::FileFormat { format } => Some(*format),
5838- _ => None,
5835+ let file_format = if let Some(ref hf) = hive_formats {
5836+ if let Some(ref ff) = hf.storage {
5837+ match ff {
5838+ HiveIOFormat::FileFormat { format } => Some(*format),
5839+ _ => None,
5840+ }
5841+ } else {
5842+ None
58395843 }
58405844 } else {
58415845 None
58425846 };
5843- let location = hive_formats.location.clone();
5847+ let location = hive_formats.as_ref().and_then(|hf| hf. location.clone() );
58445848 let table_properties = self.parse_options(Keyword::TBLPROPERTIES)?;
58455849 let table_options = if !table_properties.is_empty() {
58465850 CreateTableOptions::TableProperties(table_properties)
@@ -5851,7 +5855,7 @@ impl<'a> Parser<'a> {
58515855 .columns(columns)
58525856 .constraints(constraints)
58535857 .hive_distribution(hive_distribution)
5854- .hive_formats(Some( hive_formats) )
5858+ .hive_formats(hive_formats)
58555859 .table_options(table_options)
58565860 .or_replace(or_replace)
58575861 .if_not_exists(if_not_exists)
@@ -6768,9 +6772,11 @@ impl<'a> Parser<'a> {
67686772 return self.parse_drop_trigger();
67696773 } else if self.parse_keyword(Keyword::EXTENSION) {
67706774 return self.parse_drop_extension();
6775+ } else if self.parse_keyword(Keyword::OPERATOR) {
6776+ return self.parse_drop_operator();
67716777 } else {
67726778 return self.expected(
6773- "CONNECTOR, DATABASE, EXTENSION, FUNCTION, INDEX, POLICY, PROCEDURE, ROLE, SCHEMA, SECRET, SEQUENCE, STAGE, TABLE, TRIGGER, TYPE, VIEW, MATERIALIZED VIEW or USER after DROP",
6779+ "CONNECTOR, DATABASE, EXTENSION, FUNCTION, INDEX, OPERATOR, POLICY, PROCEDURE, ROLE, SCHEMA, SECRET, SEQUENCE, STAGE, TABLE, TRIGGER, TYPE, VIEW, MATERIALIZED VIEW or USER after DROP",
67746780 self.peek_token(),
67756781 );
67766782 };
@@ -7526,6 +7532,46 @@ impl<'a> Parser<'a> {
75267532 }))
75277533 }
75287534
7535+ /// Parse a[Statement::DropOperator] statement.
7536+ ///
7537+ pub fn parse_drop_operator(&mut self) -> Result<Statement, ParserError> {
7538+ let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);
7539+ let operators = self.parse_comma_separated(|p| p.parse_drop_operator_signature())?;
7540+ let drop_behavior = self.parse_optional_drop_behavior();
7541+ Ok(Statement::DropOperator(DropOperator {
7542+ if_exists,
7543+ operators,
7544+ drop_behavior,
7545+ }))
7546+ }
7547+
7548+ /// Parse an operator signature for a [Statement::DropOperator]
7549+ /// Format: `name ( { left_type | NONE } , right_type )`
7550+ fn parse_drop_operator_signature(&mut self) -> Result<DropOperatorSignature, ParserError> {
7551+ let name = self.parse_operator_name()?;
7552+ self.expect_token(&Token::LParen)?;
7553+
7554+ // Parse left operand type (or NONE for prefix operators)
7555+ let left_type = if self.parse_keyword(Keyword::NONE) {
7556+ None
7557+ } else {
7558+ Some(self.parse_data_type()?)
7559+ };
7560+
7561+ self.expect_token(&Token::Comma)?;
7562+
7563+ // Parse right operand type (always required)
7564+ let right_type = self.parse_data_type()?;
7565+
7566+ self.expect_token(&Token::RParen)?;
7567+
7568+ Ok(DropOperatorSignature {
7569+ name,
7570+ left_type,
7571+ right_type,
7572+ })
7573+ }
7574+
75297575 //TODO: Implement parsing for Skewed
75307576 pub fn parse_hive_distribution(&mut self) -> Result<HiveDistributionStyle, ParserError> {
75317577 if self.parse_keywords(&[Keyword::PARTITIONED, Keyword::BY]) {
@@ -7538,8 +7584,8 @@ impl<'a> Parser<'a> {
75387584 }
75397585 }
75407586
7541- pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError> {
7542- let mut hive_format = HiveFormat::default() ;
7587+ pub fn parse_hive_formats(&mut self) -> Result<Option< HiveFormat> , ParserError> {
7588+ let mut hive_format: Option<HiveFormat> = None ;
75437589 loop {
75447590 match self.parse_one_of_keywords(&[
75457591 Keyword::ROW,
@@ -7548,32 +7594,39 @@ impl<'a> Parser<'a> {
75487594 Keyword::WITH,
75497595 ]) {
75507596 Some(Keyword::ROW) => {
7551- hive_format.row_format = Some(self.parse_row_format()?);
7597+ hive_format
7598+ .get_or_insert_with(HiveFormat::default)
7599+ .row_format = Some(self.parse_row_format()?);
75527600 }
75537601 Some(Keyword::STORED) => {
75547602 self.expect_keyword_is(Keyword::AS)?;
75557603 if self.parse_keyword(Keyword::INPUTFORMAT) {
75567604 let input_format = self.parse_expr()?;
75577605 self.expect_keyword_is(Keyword::OUTPUTFORMAT)?;
75587606 let output_format = self.parse_expr()?;
7559- hive_format.storage = Some(HiveIOFormat::IOF {
7560- input_format,
7561- output_format,
7562- });
7607+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7608+ Some(HiveIOFormat::IOF {
7609+ input_format,
7610+ output_format,
7611+ });
75637612 } else {
75647613 let format = self.parse_file_format()?;
7565- hive_format.storage = Some(HiveIOFormat::FileFormat { format });
7614+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7615+ Some(HiveIOFormat::FileFormat { format });
75667616 }
75677617 }
75687618 Some(Keyword::LOCATION) => {
7569- hive_format.location = Some(self.parse_literal_string()?);
7619+ hive_format.get_or_insert_with(HiveFormat::default).location =
7620+ Some(self.parse_literal_string()?);
75707621 }
75717622 Some(Keyword::WITH) => {
75727623 self.prev_token();
75737624 let properties = self
75747625 .parse_options_with_keywords(&[Keyword::WITH, Keyword::SERDEPROPERTIES])?;
75757626 if !properties.is_empty() {
7576- hive_format.serde_properties = Some(properties);
7627+ hive_format
7628+ .get_or_insert_with(HiveFormat::default)
7629+ .serde_properties = Some(properties);
75777630 } else {
75787631 break;
75797632 }
@@ -7788,7 +7841,7 @@ impl<'a> Parser<'a> {
77887841 .if_not_exists(if_not_exists)
77897842 .transient(transient)
77907843 .hive_distribution(hive_distribution)
7791- .hive_formats(Some( hive_formats) )
7844+ .hive_formats(hive_formats)
77927845 .global(global)
77937846 .query(query)
77947847 .without_rowid(without_rowid)
0 commit comments