Skip to content

Commit

Permalink
fix(sqlparser): array of struct of struct (#19483)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjinwu authored and xiangjinwu committed Nov 22, 2024
1 parent 12f67bc commit ec421b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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
3 changes: 3 additions & 0 deletions src/sqlparser/tests/testdata/array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@
sql parser error: expected an expression, found: [
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(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 ec421b5

Please sign in to comment.