Skip to content

Commit

Permalink
Fix to support ARRAY<PROTO> (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb authored Dec 20, 2024
1 parent 0230ae2 commit 8c62184
Show file tree
Hide file tree
Showing 5 changed files with 810 additions and 213 deletions.
2 changes: 1 addition & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3447,7 +3447,7 @@ type ArraySchemaType struct {
Gt token.Pos // position of ">"
Rparen token.Pos // position of ")" when len(NamedArgs) > 0

Item SchemaType // ScalarSchemaType or SizedSchemaType
Item SchemaType // ScalarSchemaType or SizedSchemaType or NamedType
NamedArgs []*NamedArg
}

Expand Down
8 changes: 5 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4424,9 +4424,6 @@ func (p *Parser) tryParseTablePrivilegeColumns() ([]*ast.Ident, token.Pos) {
func (p *Parser) parseSchemaType() ast.SchemaType {
switch p.Token.Kind {
case token.TokenIdent:
if !p.lookaheadSimpleType() {
return p.parseNamedType()
}
return p.parseScalarSchemaType()
case "ARRAY":
pos := p.expect("ARRAY").Pos
Expand Down Expand Up @@ -4574,7 +4571,12 @@ var sizedSchemaTypes = []string{
"BYTES",
}

// parseScalarSchemaType parses ScalarSchemaType, SizedSchemaType and NamedType, but not ArraySchemaType.
func (p *Parser) parseScalarSchemaType() ast.SchemaType {
if !p.lookaheadSimpleType() {
return p.parseNamedType()
}

id := p.expect(token.TokenIdent)
pos := id.Pos

Expand Down
19 changes: 16 additions & 3 deletions testdata/input/ddl/create_table_types.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
-- https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#data_types
create table types (
b bool,
i int64,
f32 float32,
f float64,
d date,
t timestamp,
s string(256),
sh string(0x100),
smax string(max),
bs bytes(256),
bh bytes(0x100),
bsmax bytes(max),
j json,
d date,
t timestamp,
ab array<bool>,
abs array<bytes(max)>,
p examples.ProtoType,
af32vl array<float32>(vector_length=>128),
p ProtoType,
p_quoted `ProtoType`,
p_path examples.ProtoType,
p_partly_quoted_path examples.shipping.`Order`,
p_fully_quoted_path `examples.shipping.Order`,
ap ARRAY<ProtoType>,
ap_quoted ARRAY<`ProtoType`>,
ap_path ARRAY<examples.ProtoType>,
ap_partly_quoted_path ARRAY<examples.shipping.`Order`>,
ap_fully_quoted_path ARRAY<`examples.shipping.Order`>,
) primary key (i)
Loading

0 comments on commit 8c62184

Please sign in to comment.