@@ -5831,15 +5831,19 @@ impl<'a> Parser<'a> {
58315831 let hive_distribution = self.parse_hive_distribution()?;
58325832 let hive_formats = self.parse_hive_formats()?;
58335833
5834- let file_format = if let Some(ff) = &hive_formats.storage {
5835- match ff {
5836- HiveIOFormat::FileFormat { format } => Some(*format),
5837- _ => None,
5834+ let file_format = if let Some(ref hf) = hive_formats {
5835+ if let Some(ref ff) = hf.storage {
5836+ match ff {
5837+ HiveIOFormat::FileFormat { format } => Some(*format),
5838+ _ => None,
5839+ }
5840+ } else {
5841+ None
58385842 }
58395843 } else {
58405844 None
58415845 };
5842- let location = hive_formats.location.clone();
5846+ let location = hive_formats.as_ref().and_then(|hf| hf. location.clone() );
58435847 let table_properties = self.parse_options(Keyword::TBLPROPERTIES)?;
58445848 let table_options = if !table_properties.is_empty() {
58455849 CreateTableOptions::TableProperties(table_properties)
@@ -5850,7 +5854,7 @@ impl<'a> Parser<'a> {
58505854 .columns(columns)
58515855 .constraints(constraints)
58525856 .hive_distribution(hive_distribution)
5853- .hive_formats(Some( hive_formats) )
5857+ .hive_formats(hive_formats)
58545858 .table_options(table_options)
58555859 .or_replace(or_replace)
58565860 .if_not_exists(if_not_exists)
@@ -7537,8 +7541,8 @@ impl<'a> Parser<'a> {
75377541 }
75387542 }
75397543
7540- pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError> {
7541- let mut hive_format = HiveFormat::default() ;
7544+ pub fn parse_hive_formats(&mut self) -> Result<Option< HiveFormat> , ParserError> {
7545+ let mut hive_format: Option<HiveFormat> = None ;
75427546 loop {
75437547 match self.parse_one_of_keywords(&[
75447548 Keyword::ROW,
@@ -7547,32 +7551,39 @@ impl<'a> Parser<'a> {
75477551 Keyword::WITH,
75487552 ]) {
75497553 Some(Keyword::ROW) => {
7550- hive_format.row_format = Some(self.parse_row_format()?);
7554+ hive_format
7555+ .get_or_insert_with(HiveFormat::default)
7556+ .row_format = Some(self.parse_row_format()?);
75517557 }
75527558 Some(Keyword::STORED) => {
75537559 self.expect_keyword_is(Keyword::AS)?;
75547560 if self.parse_keyword(Keyword::INPUTFORMAT) {
75557561 let input_format = self.parse_expr()?;
75567562 self.expect_keyword_is(Keyword::OUTPUTFORMAT)?;
75577563 let output_format = self.parse_expr()?;
7558- hive_format.storage = Some(HiveIOFormat::IOF {
7559- input_format,
7560- output_format,
7561- });
7564+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7565+ Some(HiveIOFormat::IOF {
7566+ input_format,
7567+ output_format,
7568+ });
75627569 } else {
75637570 let format = self.parse_file_format()?;
7564- hive_format.storage = Some(HiveIOFormat::FileFormat { format });
7571+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7572+ Some(HiveIOFormat::FileFormat { format });
75657573 }
75667574 }
75677575 Some(Keyword::LOCATION) => {
7568- hive_format.location = Some(self.parse_literal_string()?);
7576+ hive_format.get_or_insert_with(HiveFormat::default).location =
7577+ Some(self.parse_literal_string()?);
75697578 }
75707579 Some(Keyword::WITH) => {
75717580 self.prev_token();
75727581 let properties = self
75737582 .parse_options_with_keywords(&[Keyword::WITH, Keyword::SERDEPROPERTIES])?;
75747583 if !properties.is_empty() {
7575- hive_format.serde_properties = Some(properties);
7584+ hive_format
7585+ .get_or_insert_with(HiveFormat::default)
7586+ .serde_properties = Some(properties);
75767587 } else {
75777588 break;
75787589 }
@@ -7787,7 +7798,7 @@ impl<'a> Parser<'a> {
77877798 .if_not_exists(if_not_exists)
77887799 .transient(transient)
77897800 .hive_distribution(hive_distribution)
7790- .hive_formats(Some( hive_formats) )
7801+ .hive_formats(hive_formats)
77917802 .global(global)
77927803 .query(query)
77937804 .without_rowid(without_rowid)
0 commit comments