Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlparser): array of struct of struct #19483

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>[])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case seems to work in current version. Did I miss something?

dev=> CREATE TABLE t (params STRUCT<a STRUCT<b int>>[])
dev-> ;
CREATE_TABLE
dev=> describe t;
┌───────────────────┬─────────────────────┬───────────┬─────────────┐
│       Name        │        Type         │ Is Hidden │ Description │
├───────────────────┼─────────────────────┼───────────┼─────────────┤
│ params            │                     │ false     │ ∅           │
│ params.a          │ struct<b integer>[] │ false     │ ∅           │
│ _row_id           │ serial              │ true      │ ∅           │
│ primary key       │ _row_id             │ ∅         │ ∅           │
│ distribution key  │ _row_id             │ ∅         │ ∅           │
│ table description │ t                   │ ∅         │ ∅           │
└───────────────────┴─────────────────────┴───────────┴─────────────┘
(6 rows)

Copy link
Member

@xxchan xxchan Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's wrong

dev=> show create table t;
┌──────────┬───────────────────────────────────────────────────┐
│   Name   │                    Create Sql                     │
├──────────┼───────────────────────────────────────────────────┤
│ public.t │ CREATE TABLE t (params STRUCT<a STRUCT<b INT>[]>) │
└──────────┴───────────────────────────────────────────────────┘

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you find the bug? Is it related with other bugs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the linked issue. It was causing a schema mismatch panic when sink into table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't notice there's linked issue since there's no fix #xx in body 😄

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: [] }'
Loading