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

feat: support nested array schema #2734

Merged
merged 2 commits into from
Mar 27, 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
14 changes: 14 additions & 0 deletions internal/xsql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,20 @@
return nil, fmt.Errorf("found %q, expect rparen in struct of array type definition.", lit2)
}
}
} else if t == ast.ARRAY {
if f, err := p.parseStreamArrayType(); err != nil {
return nil, err

Check warning on line 1460 in internal/xsql/parser.go

View check run for this annotation

Codecov / codecov/patch

internal/xsql/parser.go#L1460

Added line #L1460 was not covered by tests
} else {
if tok2, lit2 := p.scanIgnoreWhitespace(); tok2 == ast.RPAREN {
lStack.Pop()
if lStack.Len() > 0 {
return nil, fmt.Errorf("Parenthesis is in array of array type %q not matched.", tok1)
}

Check warning on line 1466 in internal/xsql/parser.go

View check run for this annotation

Codecov / codecov/patch

internal/xsql/parser.go#L1465-L1466

Added lines #L1465 - L1466 were not covered by tests
return &ast.ArrayType{Type: ast.ARRAY, FieldType: f}, nil
} else {
return nil, fmt.Errorf("found %q, expect rparen in array of array type definition.", lit2)
}

Check warning on line 1470 in internal/xsql/parser.go

View check run for this annotation

Codecov / codecov/patch

internal/xsql/parser.go#L1468-L1470

Added lines #L1468 - L1470 were not covered by tests
}
} else if tok1 == ast.COMMA {
p.unscan()
} else {
Expand Down
21 changes: 19 additions & 2 deletions internal/xsql/parser_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ func TestParser_ParseCreateStream(t *testing.T) {
stmt *ast.StreamStmt
err string
}{
{
s: `CREATE STREAM demo(list ARRAY(ARRAY(BIGINT))) WITH (DATASOURCE="users", FORMAT="JSON")`,
stmt: &ast.StreamStmt{
Name: ast.StreamName("demo"),
StreamFields: []ast.StreamField{
{
Name: "list",
FieldType: &ast.ArrayType{
Type: ast.ARRAY,
FieldType: &ast.ArrayType{Type: ast.BIGINT},
},
},
},
Options: &ast.Options{
DATASOURCE: "users",
FORMAT: "JSON",
},
},
},
{
s: `CREATE STREAM demo (
USERID BIGINT,
Expand Down Expand Up @@ -67,7 +86,6 @@ func TestParser_ParseCreateStream(t *testing.T) {
},
},
},

{
s: `CREATE STREAM demo (
USERID BIGINT,
Expand All @@ -86,7 +104,6 @@ func TestParser_ParseCreateStream(t *testing.T) {
},
},
},

{
s: `CREATE STREAM demo (
ADDRESSES ARRAY(STRUCT(STREET_NAME STRING, NUMBER BIGINT)),
Expand Down
Loading