Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,22 @@ impl fmt::Display for Interval {
pub struct StructField {
pub field_name: Option<Ident>,
pub field_type: DataType,
/// Struct field options.
/// see [BigQuery]: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#column_name_and_column_schema
pub options: Option<Vec<SqlOption>>,
}

impl fmt::Display for StructField {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(name) = &self.field_name {
write!(f, "{name} {}", self.field_type)
write!(f, "{name} {}", self.field_type)?;
} else {
write!(f, "{}", self.field_type)
write!(f, "{}", self.field_type)?;
}
if let Some(options) = &self.options {
write!(f, " OPTIONS({})", display_separated(options, ", "))
} else {
Ok(())
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3076,6 +3076,7 @@ impl<'a> Parser<'a> {
Ok(StructField {
field_name: Some(field_name),
field_type,
options: None,
})
});
self.expect_token(&Token::RParen)?;
Expand Down Expand Up @@ -3109,10 +3110,12 @@ impl<'a> Parser<'a> {

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

let options = self.maybe_parse_options(Keyword::OPTIONS)?;
Ok((
StructField {
field_name,
field_type,
options,
},
trailing_bracket,
))
Expand Down
Loading
Loading