@@ -5862,15 +5862,19 @@ impl<'a> Parser<'a> {
58625862 let hive_distribution = self.parse_hive_distribution()?;
58635863 let hive_formats = self.parse_hive_formats()?;
58645864
5865- let file_format = if let Some(ff) = &hive_formats.storage {
5866- match ff {
5867- HiveIOFormat::FileFormat { format } => Some(*format),
5868- _ => None,
5865+ let file_format = if let Some(ref hf) = hive_formats {
5866+ if let Some(ref ff) = hf.storage {
5867+ match ff {
5868+ HiveIOFormat::FileFormat { format } => Some(*format),
5869+ _ => None,
5870+ }
5871+ } else {
5872+ None
58695873 }
58705874 } else {
58715875 None
58725876 };
5873- let location = hive_formats.location.clone();
5877+ let location = hive_formats.as_ref().and_then(|hf| hf. location.clone() );
58745878 let table_properties = self.parse_options(Keyword::TBLPROPERTIES)?;
58755879 let table_options = if !table_properties.is_empty() {
58765880 CreateTableOptions::TableProperties(table_properties)
@@ -5881,7 +5885,7 @@ impl<'a> Parser<'a> {
58815885 .columns(columns)
58825886 .constraints(constraints)
58835887 .hive_distribution(hive_distribution)
5884- .hive_formats(Some( hive_formats) )
5888+ .hive_formats(hive_formats)
58855889 .table_options(table_options)
58865890 .or_replace(or_replace)
58875891 .if_not_exists(if_not_exists)
@@ -7610,8 +7614,8 @@ impl<'a> Parser<'a> {
76107614 }
76117615 }
76127616
7613- pub fn parse_hive_formats(&mut self) -> Result<HiveFormat, ParserError> {
7614- let mut hive_format = HiveFormat::default() ;
7617+ pub fn parse_hive_formats(&mut self) -> Result<Option< HiveFormat> , ParserError> {
7618+ let mut hive_format: Option<HiveFormat> = None ;
76157619 loop {
76167620 match self.parse_one_of_keywords(&[
76177621 Keyword::ROW,
@@ -7620,32 +7624,39 @@ impl<'a> Parser<'a> {
76207624 Keyword::WITH,
76217625 ]) {
76227626 Some(Keyword::ROW) => {
7623- hive_format.row_format = Some(self.parse_row_format()?);
7627+ hive_format
7628+ .get_or_insert_with(HiveFormat::default)
7629+ .row_format = Some(self.parse_row_format()?);
76247630 }
76257631 Some(Keyword::STORED) => {
76267632 self.expect_keyword_is(Keyword::AS)?;
76277633 if self.parse_keyword(Keyword::INPUTFORMAT) {
76287634 let input_format = self.parse_expr()?;
76297635 self.expect_keyword_is(Keyword::OUTPUTFORMAT)?;
76307636 let output_format = self.parse_expr()?;
7631- hive_format.storage = Some(HiveIOFormat::IOF {
7632- input_format,
7633- output_format,
7634- });
7637+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7638+ Some(HiveIOFormat::IOF {
7639+ input_format,
7640+ output_format,
7641+ });
76357642 } else {
76367643 let format = self.parse_file_format()?;
7637- hive_format.storage = Some(HiveIOFormat::FileFormat { format });
7644+ hive_format.get_or_insert_with(HiveFormat::default).storage =
7645+ Some(HiveIOFormat::FileFormat { format });
76387646 }
76397647 }
76407648 Some(Keyword::LOCATION) => {
7641- hive_format.location = Some(self.parse_literal_string()?);
7649+ hive_format.get_or_insert_with(HiveFormat::default).location =
7650+ Some(self.parse_literal_string()?);
76427651 }
76437652 Some(Keyword::WITH) => {
76447653 self.prev_token();
76457654 let properties = self
76467655 .parse_options_with_keywords(&[Keyword::WITH, Keyword::SERDEPROPERTIES])?;
76477656 if !properties.is_empty() {
7648- hive_format.serde_properties = Some(properties);
7657+ hive_format
7658+ .get_or_insert_with(HiveFormat::default)
7659+ .serde_properties = Some(properties);
76497660 } else {
76507661 break;
76517662 }
@@ -7860,7 +7871,7 @@ impl<'a> Parser<'a> {
78607871 .if_not_exists(if_not_exists)
78617872 .transient(transient)
78627873 .hive_distribution(hive_distribution)
7863- .hive_formats(Some( hive_formats) )
7874+ .hive_formats(hive_formats)
78647875 .global(global)
78657876 .query(query)
78667877 .without_rowid(without_rowid)
0 commit comments