From 5bc791aeb178d6b301ace09592cafe635ffd8bc5 Mon Sep 17 00:00:00 2001 From: Ayman Elkfrawy Date: Sat, 23 Nov 2024 13:42:05 -0800 Subject: [PATCH] address comments --- src/ast/mod.rs | 6 ++++-- src/parser/mod.rs | 20 ++++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index b66a83da0..624344375 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -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, - /// BigQuery specific: Struct field definitions. - /// see https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type + /// Struct field definitions. fields: Vec, }, /// `BigQuery` specific: An named expression in a typeless struct [1] diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 339b73125..a7549842c 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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 { - 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()))?;