Skip to content

Commit c202f68

Browse files
committed
use auto_increment for SERAIL type
1 parent f397b9a commit c202f68

File tree

12 files changed

+33
-60
lines changed

12 files changed

+33
-60
lines changed

go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ require (
66
github.com/PuerkitoBio/goquery v1.8.1
77
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
88
github.com/cockroachdb/errors v1.7.5
9-
github.com/dolthub/dolt/go v0.40.5-0.20240326182628-9d43ca67ab53
9+
github.com/dolthub/dolt/go v0.40.5-0.20240403070247-e5fbbdc22482
1010
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240228231039-f903736a64a8
11-
github.com/dolthub/go-mysql-server v0.18.1-0.20240326173717-f57423646998
11+
github.com/dolthub/go-mysql-server v0.18.1-0.20240402212936-10d3bfe2a2d5
1212
github.com/dolthub/sqllogictest/go v0.0.0-20240118211725-a52e3f5697e3
13-
github.com/dolthub/vitess v0.0.0-20240325235243-65f4774a8706
13+
github.com/dolthub/vitess v0.0.0-20240329223145-3e53a7bee1da
1414
github.com/fatih/color v1.13.0
1515
github.com/gogo/protobuf v1.3.2
1616
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35
@@ -152,6 +152,7 @@ require (
152152
google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect
153153
google.golang.org/grpc v1.57.1 // indirect
154154
google.golang.org/protobuf v1.31.0 // indirect
155+
gopkg.in/errgo.v2 v2.1.0 // indirect
155156
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
156157
gopkg.in/yaml.v3 v3.0.1 // indirect
157158
)

go.sum

+7-6
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
214214
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
215215
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
216216
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
217-
github.com/dolthub/dolt/go v0.40.5-0.20240326182628-9d43ca67ab53 h1:BGsave9hwSTo/snmGQ+pxfvrXr4jmeNArX2l03lAIbI=
218-
github.com/dolthub/dolt/go v0.40.5-0.20240326182628-9d43ca67ab53/go.mod h1:3sDzanwEQnbnL3WXjKVGIdBP/uwMm6CiafH0estgllg=
217+
github.com/dolthub/dolt/go v0.40.5-0.20240403070247-e5fbbdc22482 h1:K+UG61csglnDIZWWllOYhoL9QobOzhIuDPGGC4aGzGs=
218+
github.com/dolthub/dolt/go v0.40.5-0.20240403070247-e5fbbdc22482/go.mod h1:vFVZn5dl2uWTtOYhfVbzqReRKNZTAwqnB2jMPdMwAAw=
219219
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240228231039-f903736a64a8 h1:7GAc45zje/43KeNMX4zBcdCShLdqJhyVQvLDWoxvA+s=
220220
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240228231039-f903736a64a8/go.mod h1:gHeHIDGU7em40EhFTliq62pExFcc1hxDTIZ9g5UqXYM=
221221
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
@@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
224224
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
225225
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
226226
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
227-
github.com/dolthub/go-mysql-server v0.18.1-0.20240326173717-f57423646998 h1:mW5rmY0D0DSek6/UW0uu3B1h84Fttk+Y9Dee1abLAM8=
228-
github.com/dolthub/go-mysql-server v0.18.1-0.20240326173717-f57423646998/go.mod h1:99WjL4v4Ozkona7YowHl20+1B5DPhDbVZnf7WP+TX1U=
227+
github.com/dolthub/go-mysql-server v0.18.1-0.20240402212936-10d3bfe2a2d5 h1:ly4Zz6prRZKUcF17At3bQo/uGbxd2I0uTTgLPB2Hxhc=
228+
github.com/dolthub/go-mysql-server v0.18.1-0.20240402212936-10d3bfe2a2d5/go.mod h1:SJleIOwC74u9tdUoGgVgM/eLlwVj3sJEFfx0sdStvW0=
229229
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514=
230230
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto=
231231
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTEtT5tOBsCuCrlYnLRKpbJVJkDbrTRhwQ=
@@ -236,8 +236,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240118211725-a52e3f5697e3 h1:+eDpuEJ
236236
github.com/dolthub/sqllogictest/go v0.0.0-20240118211725-a52e3f5697e3/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
237237
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
238238
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
239-
github.com/dolthub/vitess v0.0.0-20240325235243-65f4774a8706 h1:nlmIlkMuCXzp/h5hoKh4mWW5ePqRlhwlJJQRLMtN3B4=
240-
github.com/dolthub/vitess v0.0.0-20240325235243-65f4774a8706/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
239+
github.com/dolthub/vitess v0.0.0-20240329223145-3e53a7bee1da h1:EZJqfIEHLV/eRtlxMhep2Jj/JpHSnZBiKFFLFbnmsSo=
240+
github.com/dolthub/vitess v0.0.0-20240329223145-3e53a7bee1da/go.mod h1:Xy89nzEyIwlMCiFWOJPmlnORpDFz5wFgEdYGfUwbIQ0=
241241
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
242242
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
243243
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
@@ -1370,6 +1370,7 @@ gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8
13701370
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
13711371
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
13721372
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
1373+
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
13731374
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
13741375
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
13751376
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=

server/ast/column_table_def.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ func nodeColumnTableDef(node *tree.ColumnTableDef) (_ *vitess.ColumnDefinition,
9595
generatedStored = true
9696
}
9797
// TODO: need to add support for SEQUENCE.
98-
// Unable use auto_increment using node.IsSerial value.
9998
return &vitess.ColumnDefinition{
10099
Name: vitess.NewColIdent(string(node.Name)),
101100
Type: vitess.ColumnType{
102101
Type: convertType.Type,
103102
ResolvedType: resolvedType,
104103
Null: isNull,
105104
NotNull: isNotNull,
106-
Autoincrement: false,
105+
Autoincrement: vitess.BoolVal(node.IsSerial),
107106
Default: defaultExpr,
108107
Length: convertType.Length,
109108
Scale: convertType.Scale,

server/types/float32.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ func (b Float32Type) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
5151

5252
// Compare implements the DoltgresType interface.
5353
func (b Float32Type) Compare(v1 any, v2 any) (int, error) {
54-
if v1 == nil && v2 == nil {
55-
return 0, nil
56-
} else if v1 != nil && v2 == nil {
57-
return 1, nil
58-
} else if v1 == nil && v2 != nil {
59-
return -1, nil
54+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
55+
return res, nil
6056
}
6157

6258
ac, _, err := b.Convert(v1)

server/types/float64.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ func (b Float64Type) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
5050

5151
// Compare implements the DoltgresType interface.
5252
func (b Float64Type) Compare(v1 any, v2 any) (int, error) {
53-
if v1 == nil && v2 == nil {
54-
return 0, nil
55-
} else if v1 != nil && v2 == nil {
56-
return 1, nil
57-
} else if v1 == nil && v2 != nil {
58-
return -1, nil
53+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
54+
return res, nil
5955
}
6056

6157
ac, _, err := b.Convert(v1)

server/types/int16.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ func (b Int16Type) CollationCoercibility(ctx *sql.Context) (collation sql.Collat
4949

5050
// Compare implements the DoltgresType interface.
5151
func (b Int16Type) Compare(v1 any, v2 any) (int, error) {
52-
if v1 == nil && v2 == nil {
53-
return 0, nil
54-
} else if v1 != nil && v2 == nil {
55-
return 1, nil
56-
} else if v1 == nil && v2 != nil {
57-
return -1, nil
52+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
53+
return res, nil
5854
}
5955

6056
ac, _, err := b.Convert(v1)

server/types/int32.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ func (b Int32Type) CollationCoercibility(ctx *sql.Context) (collation sql.Collat
4949

5050
// Compare implements the DoltgresType interface.
5151
func (b Int32Type) Compare(v1 any, v2 any) (int, error) {
52-
if v1 == nil && v2 == nil {
53-
return 0, nil
54-
} else if v1 != nil && v2 == nil {
55-
return 1, nil
56-
} else if v1 == nil && v2 != nil {
57-
return -1, nil
52+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
53+
return res, nil
5854
}
5955

6056
ac, _, err := b.Convert(v1)

server/types/int64.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ func (b Int64Type) CollationCoercibility(ctx *sql.Context) (collation sql.Collat
4949

5050
// Compare implements the DoltgresType interface.
5151
func (b Int64Type) Compare(v1 any, v2 any) (int, error) {
52-
if v1 == nil && v2 == nil {
53-
return 0, nil
54-
} else if v1 != nil && v2 == nil {
55-
return 1, nil
56-
} else if v1 == nil && v2 != nil {
57-
return -1, nil
52+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
53+
return res, nil
5854
}
5955

6056
ac, _, err := b.Convert(v1)

server/types/numeric.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@ func (b NumericType) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
5858

5959
// Compare implements the DoltgresType interface.
6060
func (b NumericType) Compare(v1 any, v2 any) (int, error) {
61-
if v1 == nil && v2 == nil {
62-
return 0, nil
63-
} else if v1 != nil && v2 == nil {
64-
return 1, nil
65-
} else if v1 == nil && v2 != nil {
66-
return -1, nil
61+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
62+
return res, nil
6763
}
6864

6965
ac, _, err := b.Convert(v1)

server/types/uuid.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ func (b UuidType) CollationCoercibility(ctx *sql.Context) (collation sql.Collati
4747

4848
// Compare implements the DoltgresType interface.
4949
func (b UuidType) Compare(v1 any, v2 any) (int, error) {
50-
if v1 == nil && v2 == nil {
51-
return 0, nil
52-
} else if v1 != nil && v2 == nil {
53-
return 1, nil
54-
} else if v1 == nil && v2 != nil {
55-
return -1, nil
50+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
51+
return res, nil
5652
}
5753

5854
ac, _, err := b.Convert(v1)

server/types/varchar.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ func (b VarCharType) CollationCoercibility(ctx *sql.Context) (collation sql.Coll
5959

6060
// Compare implements the DoltgresType interface.
6161
func (b VarCharType) Compare(v1 any, v2 any) (int, error) {
62-
if v1 == nil && v2 == nil {
63-
return 0, nil
64-
} else if v1 != nil && v2 == nil {
65-
return 1, nil
66-
} else if v1 == nil && v2 != nil {
67-
return -1, nil
62+
if hasNulls, res := types.CompareNulls(v1, v2); hasNulls {
63+
return res, nil
6864
}
6965

7066
ac, _, err := b.Convert(v1)

testing/go/regression_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ func TestRegressions(t *testing.T) {
207207
Name: "SERIAL type column definition",
208208
Assertions: []ScriptTestAssertion{
209209
{
210-
Query: "CREATE TABLE sbtest1(id SERIAL, k INTEGER DEFAULT '0' NOT NULL, c CHAR(120) DEFAULT '' NOT NULL, pad CHAR(60) DEFAULT '' NOT NULL);",
210+
Query: "CREATE TABLE sbtest1(id SERIAL, k INTEGER DEFAULT '0' NOT NULL, c CHAR(120) DEFAULT '' NOT NULL, pad CHAR(60) DEFAULT '' NOT NULL, PRIMARY KEY (id));",
211+
Expected: []sql.Row{},
212+
},
213+
{
214+
Query: "INSERT INTO sbtest1(k, c, pad) VALUES(4284, '8386864191', '67847967371'),(9261, '339736817', '3861551598704');",
211215
Expected: []sql.Row{},
212216
},
213217
},

0 commit comments

Comments
 (0)