Skip to content

Commit 5ca4524

Browse files
committed
address comments and remove typed struct flag
1 parent e5bf6a1 commit 5ca4524

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
@@ -2370,25 +2370,21 @@ impl<'a> Parser<'a> {
23702370

23712371
/// Syntax
23722372
/// ```sql
2373-
/// -- typed, specific to bigquery
2373+
/// -- typed
23742374
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
23752375
/// -- typeless
23762376
/// STRUCT( expr1 [AS field_name] [, ... ])
23772377
/// ```
23782378
fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2379-
let mut fields = vec![];
2380-
// Typed struct syntax is only supported by BigQuery
2381-
// https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
2382-
if self.dialect.supports_typed_struct_syntax() {
2383-
self.prev_token();
2384-
let trailing_bracket;
2385-
(fields, trailing_bracket) =
2386-
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2387-
if trailing_bracket.0 {
2388-
return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
2389-
}
2379+
// Parse the fields definition if exist `<[field_name] field_type, ...>`
2380+
self.prev_token();
2381+
let (fields, trailing_bracket) =
2382+
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2383+
if trailing_bracket.0 {
2384+
return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
23902385
}
23912386

2387+
// Parse the struct values `(expr1 [, ... ])`
23922388
self.expect_token(&Token::LParen)?;
23932389
let values = self
23942390
.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
@@ -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)