Skip to content

Commit b1b379e

Browse files
git-hulkiffyio
andauthored
Add support of parsing struct field's options in BigQuery (#1890)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
1 parent be30697 commit b1b379e

File tree

5 files changed

+138
-52
lines changed

5 files changed

+138
-52
lines changed

src/ast/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,22 @@ impl fmt::Display for Interval {
428428
pub struct StructField {
429429
pub field_name: Option<Ident>,
430430
pub field_type: DataType,
431+
/// Struct field options.
432+
/// See [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#column_name_and_column_schema)
433+
pub options: Option<Vec<SqlOption>>,
431434
}
432435

433436
impl fmt::Display for StructField {
434437
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
435438
if let Some(name) = &self.field_name {
436-
write!(f, "{name} {}", self.field_type)
439+
write!(f, "{name} {}", self.field_type)?;
437440
} else {
438-
write!(f, "{}", self.field_type)
441+
write!(f, "{}", self.field_type)?;
442+
}
443+
if let Some(options) = &self.options {
444+
write!(f, " OPTIONS({})", display_separated(options, ", "))
445+
} else {
446+
Ok(())
439447
}
440448
}
441449
}

src/parser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,7 @@ impl<'a> Parser<'a> {
30763076
Ok(StructField {
30773077
field_name: Some(field_name),
30783078
field_type,
3079+
options: None,
30793080
})
30803081
});
30813082
self.expect_token(&Token::RParen)?;
@@ -3109,10 +3110,12 @@ impl<'a> Parser<'a> {
31093110

31103111
let (field_type, trailing_bracket) = self.parse_data_type_helper()?;
31113112

3113+
let options = self.maybe_parse_options(Keyword::OPTIONS)?;
31123114
Ok((
31133115
StructField {
31143116
field_name,
31153117
field_type,
3118+
options,
31163119
},
31173120
trailing_bracket,
31183121
))

0 commit comments

Comments
 (0)