Skip to content

Commit 3a252ad

Browse files
committed
address comments and remove typed struct flag
1 parent 3c7fd73 commit 3a252ad

File tree

6 files changed

+14
-45
lines changed

6 files changed

+14
-45
lines changed

src/ast/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -857,12 +857,14 @@ pub enum Expr {
857857
/// Syntax:
858858
/// ```sql
859859
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
860+
///
861+
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type)
862+
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/functions/struct.html)
860863
/// ```
861864
Struct {
862865
/// Struct values.
863866
values: Vec<Expr>,
864-
/// BigQuery specific: Struct field definitions.
865-
/// see https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type
867+
/// Struct field definitions.
866868
fields: Vec<StructField>,
867869
},
868870
/// `BigQuery` specific: An named expression in a typeless struct [1]

src/dialect/bigquery.rs

-5
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,4 @@ impl Dialect for BigQueryDialect {
7777
fn supports_struct_literal(&self) -> bool {
7878
true
7979
}
80-
81-
// See https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
82-
fn supports_typed_struct_syntax(&self) -> bool {
83-
true
84-
}
8580
}

src/dialect/generic.rs

-4
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,4 @@ impl Dialect for GenericDialect {
127127
fn supports_struct_literal(&self) -> bool {
128128
true
129129
}
130-
131-
fn supports_typed_struct_syntax(&self) -> bool {
132-
true
133-
}
134130
}

src/dialect/mod.rs

-10
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,6 @@ pub trait Dialect: Debug + Any {
375375
false
376376
}
377377

378-
/// Return true if the dialect supports typed struct syntax
379-
///
380-
/// Example for bigquery
381-
/// ```sql
382-
/// SELECT STRUCT<x int64, y string>(1, 'foo')
383-
/// ```
384-
fn supports_typed_struct_syntax(&self) -> bool {
385-
false
386-
}
387-
388378
/// Dialect-specific infix parser override
389379
///
390380
/// This method is called to parse the next infix expression.

src/parser/mod.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -2329,25 +2329,21 @@ impl<'a> Parser<'a> {
23292329

23302330
/// Syntax
23312331
/// ```sql
2332-
/// -- typed, specific to bigquery
2332+
/// -- typed
23332333
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
23342334
/// -- typeless
23352335
/// STRUCT( expr1 [AS field_name] [, ... ])
23362336
/// ```
23372337
fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2338-
let mut fields = vec![];
2339-
// Typed struct syntax is only supported by BigQuery
2340-
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
2341-
if self.dialect.supports_typed_struct_syntax() {
2342-
self.prev_token();
2343-
let trailing_bracket;
2344-
(fields, trailing_bracket) =
2345-
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2346-
if trailing_bracket.0 {
2347-
return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
2348-
}
2338+
// Parse the fields definition if exist `<[field_name] field_type, ...>`
2339+
self.prev_token();
2340+
let (fields, trailing_bracket) =
2341+
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2342+
if trailing_bracket.0 {
2343+
return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
23492344
}
23502345

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

tests/sqlparser_databricks.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn parse_use() {
281281
#[test]
282282
fn parse_databricks_struct_function() {
283283
assert_eq!(
284-
databricks()
284+
databricks_and_generic()
285285
.verified_only_select("SELECT STRUCT(1, 'foo')")
286286
.projection[0],
287287
SelectItem::UnnamedExpr(Expr::Struct {
@@ -293,7 +293,7 @@ fn parse_databricks_struct_function() {
293293
})
294294
);
295295
assert_eq!(
296-
databricks()
296+
databricks_and_generic()
297297
.verified_only_select("SELECT STRUCT(1 AS one, 'foo' AS foo, false)")
298298
.projection[0],
299299
SelectItem::UnnamedExpr(Expr::Struct {
@@ -312,13 +312,3 @@ fn parse_databricks_struct_function() {
312312
})
313313
);
314314
}
315-
316-
#[test]
317-
fn parse_invalid_struct_function() {
318-
assert_eq!(
319-
databricks()
320-
.parse_sql_statements("SELECT STRUCT<INT64>(1)") // This works only in BigQuery
321-
.unwrap_err(),
322-
ParserError::ParserError("Expected: (, found: <".to_string())
323-
);
324-
}

0 commit comments

Comments
 (0)