Skip to content

Commit

Permalink
check remaining_close before peeking for LBracket
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjinwu committed Nov 21, 2024
1 parent df04740 commit bdf8fd3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/sqlparser/src/parser_v2/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ fn data_type_stateful<S>(input: &mut StatefulStream<S>) -> PResult<DataType>
where
S: TokenStream,
{
let base = data_type_stateful_inner.parse_next(input)?;
// Shall not peek for `Token::LBracket` when `>>` is partially consumed.
if *input.state.remaining_close.borrow() {
return Ok(base);
}
(
data_type_stateful_inner,
empty.value(base),
repeat(0.., (Token::LBracket, cut_err(Token::RBracket))),
)
.map(|(mut dt, depth)| {
Expand Down
4 changes: 2 additions & 2 deletions src/sqlparser/tests/testdata/array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@
LINE 1: SELECT [1,2]
^
- input: CREATE TABLE t (params STRUCT<a STRUCT<b int>>[])
formatted_sql: CREATE TABLE t (params STRUCT<a STRUCT<b INT>[]>)
formatted_ast: 'CreateTable { or_replace: false, temporary: false, if_not_exists: false, name: ObjectName([Ident { value: "t", quote_style: None }]), columns: [ColumnDef { name: Ident { value: "params", quote_style: None }, data_type: Some(Struct([StructField { name: Ident { value: "a", quote_style: None }, data_type: Array(Struct([StructField { name: Ident { value: "b", quote_style: None }, data_type: Int }])) }])), collation: None, options: [] }], wildcard_idx: None, constraints: [], with_options: [], format_encode: None, source_watermarks: [], append_only: false, on_conflict: None, with_version_column: None, query: None, cdc_table_info: None, include_column_options: [] }'
formatted_sql: CREATE TABLE t (params STRUCT<a STRUCT<b INT>>[])
formatted_ast: 'CreateTable { or_replace: false, temporary: false, if_not_exists: false, name: ObjectName([Ident { value: "t", quote_style: None }]), columns: [ColumnDef { name: Ident { value: "params", quote_style: None }, data_type: Some(Array(Struct([StructField { name: Ident { value: "a", quote_style: None }, data_type: Struct([StructField { name: Ident { value: "b", quote_style: None }, data_type: Int }]) }]))), collation: None, options: [] }], wildcard_idx: None, constraints: [], with_options: [], format_encode: None, source_watermarks: [], append_only: false, on_conflict: None, with_version_column: None, query: None, cdc_table_info: None, include_column_options: [] }'

0 comments on commit bdf8fd3

Please sign in to comment.