Skip to content

Commit

Permalink
reusing new error from pingcap#38740
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed Dec 27, 2022
1 parent 18f0086 commit 25aab24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func TestIssue40150(t *testing.T) {
tk.MustExec("use test")

tk.MustExec("CREATE TABLE t40150 (a int) PARTITION BY HASH (a) PARTITIONS 2")
tk.MustContainErrMsg(`alter table t40150 rename column a to c`, "[ddl:8200]Unsupported RENAME COLUMN 'a' has a partitioning function dependency and cannot be renamed")
tk.MustContainErrMsg(`alter table t40150 rename column a to c`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
}

func TestIssue40135(t *testing.T) {
Expand All @@ -468,5 +468,5 @@ func TestIssue40135(t *testing.T) {
dom.DDL().SetHook(hook)
tk.MustExec("alter table t40135 modify column a MEDIUMINT NULL DEFAULT '6243108' FIRST")

require.ErrorContains(t, checkErr, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed")
require.ErrorContains(t, checkErr, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
}
10 changes: 5 additions & 5 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4535,19 +4535,19 @@ func TestAlterModifyColumnOnPartitionedTableRename(t *testing.T) {
tk.MustExec("create database " + schemaName)
tk.MustExec("use " + schemaName)
tk.MustExec(`create table t (a int, b char) partition by range (a) (partition p0 values less than (10))`)
tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed")
tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
tk.MustExec(`drop table t`)
tk.MustExec(`create table t (a char, b char) partition by range columns (a) (partition p0 values less than ('z'))`)
tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed")
tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
tk.MustExec(`drop table t`)
tk.MustExec(`create table t (a int, b char) partition by list (a) (partition p0 values in (10))`)
tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed")
tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
tk.MustExec(`drop table t`)
tk.MustExec(`create table t (a char, b char) partition by list columns (a) (partition p0 values in ('z'))`)
tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed")
tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
tk.MustExec(`drop table t`)
tk.MustExec(`create table t (a int, b char) partition by hash (a) partitions 3`)
tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed")
tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed")
}

func TestDropPartitionKeyColumn(t *testing.T) {
Expand Down
17 changes: 4 additions & 13 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4734,7 +4734,7 @@ func GetModifiableColumnJob(
// TODO: update the partitioning columns with new names if column is renamed
// Would be an extension from MySQL which does not support it.
if col.Name.L != newCol.Name.L {
return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStackByArgs(fmt.Sprintf("Column '%s' has a partitioning function dependency and cannot be renamed", col.Name.O))
return nil, dbterror.ErrDependentByPartitionFunctional.GenWithStackByArgs(col.Name.L)
}
if !isColTypeAllowedAsPartitioningCol(newCol.FieldType) {
return nil, dbterror.ErrNotAllowedTypeInPartition.GenWithStackByArgs(newCol.Name.O)
Expand Down Expand Up @@ -5110,18 +5110,9 @@ func (d *ddl) RenameColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Al
}
}

if tbl.Meta().Partition != nil {
if pt, ok := tbl.(table.PartitionedTable); ok && pt != nil {
for _, name := range pt.GetPartitionColumnNames() {
if strings.EqualFold(name.L, oldColName.L) {
return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs(
fmt.Sprintf("RENAME COLUMN '%s' has a partitioning function dependency and cannot be renamed", oldColName.O))
}
}
} else {
return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs(
"RENAME COLUMN due to partitioned table")
}
err = checkDropColumnWithPartitionConstraint(tbl, oldColName)
if err != nil {
return errors.Trace(err)
}

tzName, tzOffset := ddlutil.GetTimeZone(ctx)
Expand Down

0 comments on commit 25aab24

Please sign in to comment.