Skip to content

Commit f078658

Browse files
authored
implement multiple table inherits (#935)
1 parent 28bca52 commit f078658

File tree

5 files changed

+100
-10
lines changed

5 files changed

+100
-10
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ require (
88
github.com/PuerkitoBio/goquery v1.8.1
99
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
1010
github.com/cockroachdb/errors v1.7.5
11-
github.com/dolthub/dolt/go v0.40.5-0.20241107181811-5fb8fb1de09f
11+
github.com/dolthub/dolt/go v0.40.5-0.20241112201149-884cb4dfd05d
1212
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241104143128-c2bb78c109df
1313
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
1414
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
15-
github.com/dolthub/go-mysql-server v0.18.2-0.20241106010546-3281d09c1f15
15+
github.com/dolthub/go-mysql-server v0.18.2-0.20241112002228-81b13e8034f2
1616
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
17-
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683
17+
github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9
1818
github.com/fatih/color v1.13.0
1919
github.com/goccy/go-json v0.10.2
2020
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 6 additions & 6 deletions
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.20241107181811-5fb8fb1de09f h1:ToPae847z15nTPgKctIQ8BxV3BeavwlFwD2+RF1ULns=
218-
github.com/dolthub/dolt/go v0.40.5-0.20241107181811-5fb8fb1de09f/go.mod h1:+dAesRR4iX14RVxtuxXEOzHSo83j1OZzJdLA23uXVk0=
217+
github.com/dolthub/dolt/go v0.40.5-0.20241112201149-884cb4dfd05d h1:SO65wh7ejG7CH8DemQ4fBNimSeeUlADI2roJPKSjjCU=
218+
github.com/dolthub/dolt/go v0.40.5-0.20241112201149-884cb4dfd05d/go.mod h1:wERbbFV05JV9OsGqUBrnCpgN3UEdMsFNGRsEDPwQZKY=
219219
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241104143128-c2bb78c109df h1:xafyaNR+hSk5TwOhmNkhhrmOZKIOkxAOCiIEUzlIybc=
220220
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241104143128-c2bb78c109df/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
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-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA=
226226
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
227-
github.com/dolthub/go-mysql-server v0.18.2-0.20241106010546-3281d09c1f15 h1:VGjaqZKfys8GeaI5uIaKr9y4XZbqMWlA5DJcgfiMHl8=
228-
github.com/dolthub/go-mysql-server v0.18.2-0.20241106010546-3281d09c1f15/go.mod h1:0xWs/FBE4xlhlOsAWoGh24SDRHemT7/U1nApu7SNRXg=
227+
github.com/dolthub/go-mysql-server v0.18.2-0.20241112002228-81b13e8034f2 h1:1ax2e+4r9ax5eiowBEIfRX7K/oZLeWxNNtt88CgnO0I=
228+
github.com/dolthub/go-mysql-server v0.18.2-0.20241112002228-81b13e8034f2/go.mod h1:sOMQzWUvHvJECzpcUxjDgV5BR/A7U+hOh596PUO2NPI=
229229
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
230230
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
231231
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
@@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
238238
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
239239
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
240240
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
241-
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683 h1:2/RJeUfNAXS7mbBnEr9C36htiCJHk5XldDPzhxtEsME=
242-
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
241+
github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9 h1:s36zDuLPuZRWC0nBCJs2Z8joP19eKEtcsIsuE8K9Kx0=
242+
github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
243243
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
244244
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
245245
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=

server/ast/create_table.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ func nodeCreateTable(ctx *Context, node *tree.CreateTable) (*vitess.DDL, error)
6464
Select: selectStmt,
6565
}
6666
}
67+
var optLike *vitess.OptLike
68+
if len(node.Inherits) > 0 {
69+
optLike = &vitess.OptLike{
70+
LikeTables: []vitess.TableName{},
71+
}
72+
for _, table := range node.Inherits {
73+
likeTable, err := nodeTableName(ctx, &table)
74+
if err != nil {
75+
return nil, err
76+
}
77+
optLike.LikeTables = append(optLike.LikeTables, likeTable)
78+
}
79+
}
6780
if node.WithNoData {
6881
return nil, fmt.Errorf("WITH NO DATA is not yet supported")
6982
}
@@ -73,10 +86,12 @@ func nodeCreateTable(ctx *Context, node *tree.CreateTable) (*vitess.DDL, error)
7386
IfNotExists: node.IfNotExists,
7487
Temporary: isTemporary,
7588
OptSelect: optSelect,
89+
OptLike: optLike,
7690
}
7791
if err = assignTableDefs(ctx, node.Defs, ddl); err != nil {
7892
return nil, err
7993
}
94+
8095
if node.PartitionBy != nil {
8196
switch node.PartitionBy.Type {
8297
case tree.PartitionByList:

server/ast/table_def.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func assignTableDef(ctx *Context, node tree.TableDef, target *vitess.DDL) error
8888
return err
8989
}
9090
target.OptLike = &vitess.OptLike{
91-
LikeTable: tableName,
91+
LikeTables: []vitess.TableName{tableName},
9292
}
9393
return nil
9494
case *tree.UniqueConstraintTableDef:

testing/go/create_table_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,78 @@ func TestCreateTable(t *testing.T) {
159159
},
160160
})
161161
}
162+
163+
func TestCreateTableInherit(t *testing.T) {
164+
RunScripts(t, []ScriptTest{
165+
{
166+
Name: "Create table with inheritance",
167+
SetUpScript: []string{
168+
"create table t1 (a int);",
169+
"create table t2 (b int);",
170+
"create table t3 (c int);",
171+
"create table t11 (a int);",
172+
},
173+
Assertions: []ScriptTestAssertion{
174+
{
175+
Query: "create table t4 (d int) inherits (t1, t2, t3);",
176+
Expected: []sql.Row{},
177+
},
178+
{
179+
Query: "insert into t4(a, b, c, d) values (1, 2, 3, 4);",
180+
Expected: []sql.Row{},
181+
},
182+
{
183+
Query: "select * from t4;",
184+
Expected: []sql.Row{
185+
{1, 2, 3, 4},
186+
},
187+
},
188+
189+
{
190+
Query: "create table t111 () inherits (t1, t11);",
191+
Expected: []sql.Row{},
192+
},
193+
{
194+
Query: "insert into t111(a) values (1);",
195+
Expected: []sql.Row{},
196+
},
197+
{
198+
Query: "select * from t111;",
199+
Expected: []sql.Row{
200+
{1},
201+
},
202+
},
203+
204+
{
205+
Query: "create table t1t1 (a int) inherits (t1);",
206+
Expected: []sql.Row{},
207+
},
208+
{
209+
Query: "insert into t1t1(a) values (1);",
210+
Expected: []sql.Row{},
211+
},
212+
{
213+
Query: "select * from t1t1;",
214+
Expected: []sql.Row{
215+
{1},
216+
},
217+
},
218+
219+
{
220+
Query: "create table TT1t1 (A int) inherits (t1);",
221+
Expected: []sql.Row{},
222+
},
223+
{
224+
Query: "insert into TT1t1(a) values (1);",
225+
Expected: []sql.Row{},
226+
},
227+
{
228+
Query: "select * from TT1t1;",
229+
Expected: []sql.Row{
230+
{1},
231+
},
232+
},
233+
},
234+
},
235+
})
236+
}

0 commit comments

Comments
 (0)