Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ayman-sigma committed Nov 23, 2024
1 parent 3c7fd73 commit 5bc791a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,12 +857,14 @@ pub enum Expr {
/// Syntax:
/// ```sql
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
///
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type)
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/functions/struct.html)
/// ```
Struct {
/// Struct values.
values: Vec<Expr>,
/// BigQuery specific: Struct field definitions.
/// see https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type
/// Struct field definitions.
fields: Vec<StructField>,
},
/// `BigQuery` specific: An named expression in a typeless struct [1]
Expand Down
20 changes: 8 additions & 12 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2329,25 +2329,21 @@ impl<'a> Parser<'a> {

/// Syntax
/// ```sql
/// -- typed, specific to bigquery
/// -- typed
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
/// -- typeless
/// STRUCT( expr1 [AS field_name] [, ... ])
/// ```
fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
let mut fields = vec![];
// Typed struct syntax is only supported by BigQuery
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
if self.dialect.supports_typed_struct_syntax() {
self.prev_token();
let trailing_bracket;
(fields, trailing_bracket) =
self.parse_struct_type_def(Self::parse_struct_field_def)?;
if trailing_bracket.0 {
return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
}
// Parse the fields definition if exist `<[field_name] field_type, ...>`
self.prev_token();
let (fields, trailing_bracket) =
self.parse_struct_type_def(Self::parse_struct_field_def)?;
if trailing_bracket.0 {
return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
}

// Parse the struct values `(expr1 [, ... ])`
self.expect_token(&Token::LParen)?;
let values = self
.parse_comma_separated(|parser| parser.parse_struct_field_expr(!fields.is_empty()))?;
Expand Down

0 comments on commit 5bc791a

Please sign in to comment.