Skip to content

Commit

Permalink
Merge pull request #12 from tomo241/master
Browse files Browse the repository at this point in the history
Fix a bug in ParseSpannerType when parsing an ARRAY data type and fix…
  • Loading branch information
snehashah16 committed Apr 3, 2023
2 parents 0a71c86 + 5377c7a commit 0236cb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions pkg/schema/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ func TestColumn(t *testing.T) {
So(x.Base, ShouldEqual, spansql.Bool)
})

Convey("String", func() {
c := NewColumn()
c.SetSpannerType("STRING")

x := c.Type()
So(x, ShouldNotBeNil)
So(x.Array, ShouldBeFalse)
So(x.Base, ShouldEqual, spansql.String)
})

Convey("String(1024)", func() {
c := NewColumn()
c.SetSpannerType("STRING(1024)")
Expand Down Expand Up @@ -116,9 +106,19 @@ func TestColumn(t *testing.T) {
So(x.Base, ShouldEqual, spansql.Date)
})

Convey("ARRAY<STRING>", func() {
Convey("ARRAY<STRING(1024)>", func() {
c := NewColumn()
c.SetSpannerType("ARRAY<STRING(1024)>")

x := c.Type()
So(x, ShouldNotBeNil)
So(x.Array, ShouldBeTrue)
So(x.Base, ShouldEqual, spansql.String)
})

Convey("ARRAY<STRING(MAX)>", func() {
c := NewColumn()
c.SetSpannerType("ARRAY<STRING>")
c.SetSpannerType("ARRAY<STRING(MAX)>")

x := c.Type()
So(x, ShouldNotBeNil)
Expand Down
10 changes: 5 additions & 5 deletions pkg/schema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func ParseSpannerType(spannerType string) spansql.Type {

dt := spannerType

if strings.HasPrefix(dt, "ARRAY<") {
ret.Array = true
dt = strings.TrimSuffix(strings.TrimPrefix(dt, "ARRAY<"), ">")
}

// separate type and length from dt with length such as STRING(32) or BYTES(256)
m := lengthRegexp.FindStringSubmatchIndex(dt)
if m != nil {
Expand All @@ -54,11 +59,6 @@ func ParseSpannerType(spannerType string) spansql.Type {
dt = dt[:m[0]] + dt[m[1]:]
}

if strings.HasPrefix(dt, "ARRAY<") {
ret.Array = true
dt = strings.TrimSuffix(strings.TrimPrefix(dt, "ARRAY<"), ">")
}

ret.Base = parseType(dt)

// Clip length for certain types
Expand Down

0 comments on commit 0236cb5

Please sign in to comment.