@@ -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)
@@ -7579,8 +7583,8 @@ impl<'a> Parser<'a> {
75797583 }
75807584 }
75817585
7582- pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError> {
7583- let mut hive_format = HiveFormat::default() ;
7586+ pub fn parse_hive_formats(&mut self) -> Result<Option< HiveFormat> , ParserError> {
7587+ let mut hive_format: Option<HiveFormat> = None ;
75847588 loop {
75857589 match self.parse_one_of_keywords(&[
75867590 Keyword::ROW,
@@ -7589,32 +7593,39 @@ impl<'a> Parser<'a> {
75897593 Keyword::WITH,
75907594 ]) {
75917595 Some(Keyword::ROW) => {
7592- hive_format.row_format = Some(self.parse_row_format()?);
7596+ hive_format
7597+ .get_or_insert_with(HiveFormat::default)
7598+ .row_format = Some(self.parse_row_format()?);
75937599 }
75947600 Some(Keyword::STORED) => {
75957601 self.expect_keyword_is(Keyword::AS)?;
75967602 if self.parse_keyword(Keyword::INPUTFORMAT) {
75977603 let input_format = self.parse_expr()?;
75987604 self.expect_keyword_is(Keyword::OUTPUTFORMAT)?;
75997605 let output_format = self.parse_expr()?;
7600- hive_format.storage = Some(HiveIOFormat::IOF {
7601- input_format,
7602- output_format,
7603- });
7606+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7607+ Some(HiveIOFormat::IOF {
7608+ input_format,
7609+ output_format,
7610+ });
76047611 } else {
76057612 let format = self.parse_file_format()?;
7606- hive_format.storage = Some(HiveIOFormat::FileFormat { format });
7613+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7614+ Some(HiveIOFormat::FileFormat { format });
76077615 }
76087616 }
76097617 Some(Keyword::LOCATION) => {
7610- hive_format.location = Some(self.parse_literal_string()?);
7618+ hive_format.get_or_insert_with(HiveFormat::default).location =
7619+ Some(self.parse_literal_string()?);
76117620 }
76127621 Some(Keyword::WITH) => {
76137622 self.prev_token();
76147623 let properties = self
76157624 .parse_options_with_keywords(&[Keyword::WITH, Keyword::SERDEPROPERTIES])?;
76167625 if !properties.is_empty() {
7617- hive_format.serde_properties = Some(properties);
7626+ hive_format
7627+ .get_or_insert_with(HiveFormat::default)
7628+ .serde_properties = Some(properties);
76187629 } else {
76197630 break;
76207631 }
@@ -7829,7 +7840,7 @@ impl<'a> Parser<'a> {
78297840 .if_not_exists(if_not_exists)
78307841 .transient(transient)
78317842 .hive_distribution(hive_distribution)
7832- .hive_formats(Some( hive_formats) )
7843+ .hive_formats(hive_formats)
78337844 .global(global)
78347845 .query(query)
78357846 .without_rowid(without_rowid)
0 commit comments