Skip to content

Commit fc553aa

Browse files
committed
address comments and remove typed struct flag
1 parent c64b31e commit fc553aa

File tree

6 files changed

+14
-45
lines changed

6 files changed

+14
-45
lines changed

src/ast/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,12 +935,14 @@ pub enum Expr {
935935
/// Syntax:
936936
/// ```sql
937937
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
938+
///
939+
/// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type)
940+
/// [Databricks](https://docs.databricks.com/en/sql/language-manual/functions/struct.html)
938941
/// ```
939942
Struct {
940943
/// Struct values.
941944
values: Vec<Expr>,
942-
/// BigQuery specific: Struct field definitions.
943-
/// see https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#struct_type
945+
/// Struct field definitions.
944946
fields: Vec<StructField>,
945947
},
946948
/// `BigQuery` specific: An named expression in a typeless struct [1]

src/dialect/bigquery.rs

Lines changed: 0 additions & 5 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,6 @@ pub trait Dialect: Debug + Any {
385385
false
386386
}
387387

388-
/// Return true if the dialect supports typed struct syntax
389-
///
390-
/// Example for bigquery
391-
/// ```sql
392-
/// SELECT STRUCT<x int64, y string>(1, 'foo')
393-
/// ```
394-
fn supports_typed_struct_syntax(&self) -> bool {
395-
false
396-
}
397-
398388
/// Dialect-specific infix parser override
399389
///
400390
/// This method is called to parse the next infix expression.

src/parser/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,28 +2384,24 @@ impl<'a> Parser<'a> {
23842384

23852385
/// Syntax
23862386
/// ```sql
2387-
/// -- typed, specific to bigquery
2387+
/// -- typed
23882388
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
23892389
/// -- typeless
23902390
/// STRUCT( expr1 [AS field_name] [, ... ])
23912391
/// ```
23922392
fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2393-
let mut fields = vec![];
2394-
// Typed struct syntax is only supported by BigQuery
2395-
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
2396-
if self.dialect.supports_typed_struct_syntax() {
2397-
self.prev_token();
2398-
let trailing_bracket;
2399-
(fields, trailing_bracket) =
2400-
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2401-
if trailing_bracket.0 {
2402-
return parser_err!(
2393+
// Parse the fields definition if exist `<[field_name] field_type, ...>`
2394+
self.prev_token();
2395+
let (fields, trailing_bracket) =
2396+
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2397+
if trailing_bracket.0 {
2398+
return parser_err!(
24032399
"unmatched > in STRUCT literal",
24042400
self.peek_token().span.start
24052401
);
2406-
}
24072402
}
24082403

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

tests/sqlparser_databricks.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ fn parse_use() {
282282
#[test]
283283
fn parse_databricks_struct_function() {
284284
assert_eq!(
285-
databricks()
285+
databricks_and_generic()
286286
.verified_only_select("SELECT STRUCT(1, 'foo')")
287287
.projection[0],
288288
SelectItem::UnnamedExpr(Expr::Struct {
@@ -294,7 +294,7 @@ fn parse_databricks_struct_function() {
294294
})
295295
);
296296
assert_eq!(
297-
databricks()
297+
databricks_and_generic()
298298
.verified_only_select("SELECT STRUCT(1 AS one, 'foo' AS foo, false)")
299299
.projection[0],
300300
SelectItem::UnnamedExpr(Expr::Struct {
@@ -313,13 +313,3 @@ fn parse_databricks_struct_function() {
313313
})
314314
);
315315
}
316-
317-
#[test]
318-
fn parse_invalid_struct_function() {
319-
assert_eq!(
320-
databricks()
321-
.parse_sql_statements("SELECT STRUCT<INT64>(1)") // This works only in BigQuery
322-
.unwrap_err(),
323-
ParserError::ParserError("Expected: (, found: <".to_string())
324-
);
325-
}

0 commit comments

Comments
 (0)