From 2d1ffde9fa0731ebc05c154f811abde43ded8b6c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:01:23 +0800 Subject: [PATCH] fix(sqlparser): array of struct of struct (#19483) (#19533) Co-authored-by: xiangjinwu <17769960+xiangjinwu@users.noreply.github.com> Co-authored-by: Xiangjin --- src/sqlparser/src/parser_v2/data_type.rs | 7 ++++++- src/sqlparser/tests/testdata/array.yaml | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/sqlparser/src/parser_v2/data_type.rs b/src/sqlparser/src/parser_v2/data_type.rs index 2544e54d1d542..73793de7e0b7e 100644 --- a/src/sqlparser/src/parser_v2/data_type.rs +++ b/src/sqlparser/src/parser_v2/data_type.rs @@ -152,8 +152,13 @@ fn data_type_stateful(input: &mut StatefulStream) -> PResult 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)| { diff --git a/src/sqlparser/tests/testdata/array.yaml b/src/sqlparser/tests/testdata/array.yaml index 20ed73ab9d910..2e676f7de141f 100644 --- a/src/sqlparser/tests/testdata/array.yaml +++ b/src/sqlparser/tests/testdata/array.yaml @@ -74,3 +74,6 @@ sql parser error: expected an expression, found: [ LINE 1: SELECT [1,2] ^ +- input: CREATE TABLE t (params STRUCT>[]) + formatted_sql: CREATE TABLE t (params STRUCT>[]) + 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: [], source_schema: None, source_watermarks: [], append_only: false, on_conflict: None, with_version_column: None, query: None, cdc_table_info: None, include_column_options: [] }'