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

implement multiple table inherits #935

Merged
merged 19 commits into from
Nov 12, 2024
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ require (
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241104143128-c2bb78c109df
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
github.com/dolthub/go-mysql-server v0.18.2-0.20241106010546-3281d09c1f15
github.com/dolthub/go-mysql-server v0.18.2-0.20241108193559-14a7c3c42a21
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683
github.com/dolthub/vitess v0.0.0-20241108004726-fd871a8e800e
github.com/fatih/color v1.13.0
github.com/goccy/go-json v0.10.2
github.com/gogo/protobuf v1.3.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA=
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.18.2-0.20241106010546-3281d09c1f15 h1:VGjaqZKfys8GeaI5uIaKr9y4XZbqMWlA5DJcgfiMHl8=
github.com/dolthub/go-mysql-server v0.18.2-0.20241106010546-3281d09c1f15/go.mod h1:0xWs/FBE4xlhlOsAWoGh24SDRHemT7/U1nApu7SNRXg=
github.com/dolthub/go-mysql-server v0.18.2-0.20241108193559-14a7c3c42a21 h1:JnVfGI7W5xA04Cv8R9wjphZDoVqVQ5bpVYcPtlqjbto=
github.com/dolthub/go-mysql-server v0.18.2-0.20241108193559-14a7c3c42a21/go.mod h1:mdsUjaedg9okGlEGEUOzCYZHfjC+ZoO6WqL7yZpX87c=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand All @@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683 h1:2/RJeUfNAXS7mbBnEr9C36htiCJHk5XldDPzhxtEsME=
github.com/dolthub/vitess v0.0.0-20241104125316-860772ba6683/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
github.com/dolthub/vitess v0.0.0-20241108004726-fd871a8e800e h1:LzLeTanHHI4h75GGqo7GVlFZsOpR6VOn5j3ug+a3+R8=
github.com/dolthub/vitess v0.0.0-20241108004726-fd871a8e800e/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
15 changes: 15 additions & 0 deletions server/ast/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ func nodeCreateTable(ctx *Context, node *tree.CreateTable) (*vitess.DDL, error)
Select: selectStmt,
}
}
var optLike *vitess.OptLike
if len(node.Inherits) > 0 {
optLike = &vitess.OptLike{
LikeTables: []vitess.TableName{},
}
for _, table := range node.Inherits {
likeTable, err := nodeTableName(ctx, &table)
if err != nil {
return nil, err
}
optLike.LikeTables = append(optLike.LikeTables, likeTable)
}
}
if node.WithNoData {
return nil, fmt.Errorf("WITH NO DATA is not yet supported")
}
Expand All @@ -73,10 +86,12 @@ func nodeCreateTable(ctx *Context, node *tree.CreateTable) (*vitess.DDL, error)
IfNotExists: node.IfNotExists,
Temporary: isTemporary,
OptSelect: optSelect,
OptLike: optLike,
}
if err = assignTableDefs(ctx, node.Defs, ddl); err != nil {
return nil, err
}

if node.PartitionBy != nil {
switch node.PartitionBy.Type {
case tree.PartitionByList:
Expand Down
2 changes: 1 addition & 1 deletion server/ast/table_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func assignTableDef(ctx *Context, node tree.TableDef, target *vitess.DDL) error
return err
}
target.OptLike = &vitess.OptLike{
LikeTable: tableName,
LikeTables: []vitess.TableName{tableName},
}
return nil
case *tree.UniqueConstraintTableDef:
Expand Down
60 changes: 60 additions & 0 deletions testing/go/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,63 @@ func TestCreateTable(t *testing.T) {
},
})
}

func TestCreateTableInherit(t *testing.T) {
RunScripts(t, []ScriptTest{
{
Name: "Create table with inheritance",
SetUpScript: []string{
"create table t1 (a int);",
"create table t2 (b int);",
"create table t3 (c int);",
"create table t11 (a int);",
},
Assertions: []ScriptTestAssertion{
{
Query: "create table t4 (d int) inherits (t1, t2, t3);",
Expected: []sql.Row{},
},
{
Query: "insert into t4 values (1, 2, 3, 4);",
jycor marked this conversation as resolved.
Show resolved Hide resolved
Expected: []sql.Row{},
},
{
Query: "select * from t4;",
Expected: []sql.Row{
{1, 2, 3, 4},
},
},

{
Query: "create table t111 () inherits (t1, t11);",
jycor marked this conversation as resolved.
Show resolved Hide resolved
Expected: []sql.Row{},
},
{
Query: "insert into t111 values (1);",
Expected: []sql.Row{},
},
{
Query: "select * from t111;",
Expected: []sql.Row{
{1},
},
},

{
Query: "create table t1t1 (a int) inherits (t1);",
jycor marked this conversation as resolved.
Show resolved Hide resolved
Expected: []sql.Row{},
},
{
Query: "insert into t1t1 values (1);",
jycor marked this conversation as resolved.
Show resolved Hide resolved
Expected: []sql.Row{},
},
{
Query: "select * from t1t1;",
Expected: []sql.Row{
{1},
},
},
},
},
})
}
Loading