diff --git a/go.mod b/go.mod index 35a3b7ea1b..398c5c5160 100644 --- a/go.mod +++ b/go.mod @@ -8,13 +8,13 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a github.com/cockroachdb/errors v1.7.5 - github.com/dolthub/dolt/go v0.40.5-0.20241107181811-5fb8fb1de09f + github.com/dolthub/dolt/go v0.40.5-0.20241112201149-884cb4dfd05d 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.20241112002228-81b13e8034f2 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-20241111235433-a20a5ab9d7c9 github.com/fatih/color v1.13.0 github.com/goccy/go-json v0.10.2 github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index 08db85792d..e4db382a2a 100644 --- a/go.sum +++ b/go.sum @@ -214,8 +214,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/dolthub/dolt/go v0.40.5-0.20241107181811-5fb8fb1de09f h1:ToPae847z15nTPgKctIQ8BxV3BeavwlFwD2+RF1ULns= -github.com/dolthub/dolt/go v0.40.5-0.20241107181811-5fb8fb1de09f/go.mod h1:+dAesRR4iX14RVxtuxXEOzHSo83j1OZzJdLA23uXVk0= +github.com/dolthub/dolt/go v0.40.5-0.20241112201149-884cb4dfd05d h1:SO65wh7ejG7CH8DemQ4fBNimSeeUlADI2roJPKSjjCU= +github.com/dolthub/dolt/go v0.40.5-0.20241112201149-884cb4dfd05d/go.mod h1:wERbbFV05JV9OsGqUBrnCpgN3UEdMsFNGRsEDPwQZKY= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241104143128-c2bb78c109df h1:xafyaNR+hSk5TwOhmNkhhrmOZKIOkxAOCiIEUzlIybc= github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241104143128-c2bb78c109df/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY= 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= 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.20241112002228-81b13e8034f2 h1:1ax2e+4r9ax5eiowBEIfRX7K/oZLeWxNNtt88CgnO0I= +github.com/dolthub/go-mysql-server v0.18.2-0.20241112002228-81b13e8034f2/go.mod h1:sOMQzWUvHvJECzpcUxjDgV5BR/A7U+hOh596PUO2NPI= 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= @@ -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-20241111235433-a20a5ab9d7c9 h1:s36zDuLPuZRWC0nBCJs2Z8joP19eKEtcsIsuE8K9Kx0= +github.com/dolthub/vitess v0.0.0-20241111235433-a20a5ab9d7c9/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= diff --git a/server/ast/create_table.go b/server/ast/create_table.go index 79cdcbb18e..c5c7e5cab2 100644 --- a/server/ast/create_table.go +++ b/server/ast/create_table.go @@ -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") } @@ -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: diff --git a/server/ast/table_def.go b/server/ast/table_def.go index 9f0bed8e77..73b0d2dec8 100644 --- a/server/ast/table_def.go +++ b/server/ast/table_def.go @@ -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: diff --git a/testing/go/create_table_test.go b/testing/go/create_table_test.go index c4f1c174fa..46adf15f49 100755 --- a/testing/go/create_table_test.go +++ b/testing/go/create_table_test.go @@ -159,3 +159,78 @@ 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(a, b, c, d) values (1, 2, 3, 4);", + Expected: []sql.Row{}, + }, + { + Query: "select * from t4;", + Expected: []sql.Row{ + {1, 2, 3, 4}, + }, + }, + + { + Query: "create table t111 () inherits (t1, t11);", + Expected: []sql.Row{}, + }, + { + Query: "insert into t111(a) values (1);", + Expected: []sql.Row{}, + }, + { + Query: "select * from t111;", + Expected: []sql.Row{ + {1}, + }, + }, + + { + Query: "create table t1t1 (a int) inherits (t1);", + Expected: []sql.Row{}, + }, + { + Query: "insert into t1t1(a) values (1);", + Expected: []sql.Row{}, + }, + { + Query: "select * from t1t1;", + Expected: []sql.Row{ + {1}, + }, + }, + + { + Query: "create table TT1t1 (A int) inherits (t1);", + Expected: []sql.Row{}, + }, + { + Query: "insert into TT1t1(a) values (1);", + Expected: []sql.Row{}, + }, + { + Query: "select * from TT1t1;", + Expected: []sql.Row{ + {1}, + }, + }, + }, + }, + }) +}