Skip to content

Commit b38ec53

Browse files
authored
Add various SET type tests (#3077)
1 parent c5c4097 commit b38ec53

File tree

2 files changed

+1261
-565
lines changed

2 files changed

+1261
-565
lines changed

enginetest/queries/alter_table_queries.go

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,232 @@ var AlterTableScripts = []ScriptTest{
10621062
},
10631063
},
10641064
},
1065+
1066+
// Enum tests
1067+
{
1068+
Name: "alter nil enum",
1069+
Dialect: "mysql",
1070+
SetUpScript: []string{
1071+
"create table xy (x int primary key, y enum ('a', 'b'));",
1072+
"insert into xy values (0, NULL),(1, 'b')",
1073+
},
1074+
Assertions: []ScriptTestAssertion{
1075+
{
1076+
Query: "alter table xy modify y enum('a','b','c')",
1077+
},
1078+
{
1079+
Query: "alter table xy modify y enum('a')",
1080+
ExpectedErr: types.ErrDataTruncatedForColumn,
1081+
},
1082+
},
1083+
},
1084+
{
1085+
Name: "alter keyless table",
1086+
Dialect: "mysql",
1087+
SetUpScript: []string{
1088+
"create table t (c1 int, c2 varchar(200), c3 enum('one', 'two'));",
1089+
"insert into t values (1, 'one', NULL);",
1090+
},
1091+
Assertions: []ScriptTestAssertion{
1092+
{
1093+
Query: `alter table t modify column c1 int unsigned`,
1094+
Expected: []sql.Row{{types.NewOkResult(0)}},
1095+
},
1096+
{
1097+
Query: "describe t;",
1098+
Expected: []sql.Row{
1099+
{"c1", "int unsigned", "YES", "", nil, ""},
1100+
{"c2", "varchar(200)", "YES", "", nil, ""},
1101+
{"c3", "enum('one','two')", "YES", "", nil, ""},
1102+
},
1103+
},
1104+
{
1105+
Query: `alter table t drop column c1;`,
1106+
Expected: []sql.Row{{types.NewOkResult(0)}},
1107+
},
1108+
{
1109+
Query: "describe t;",
1110+
Expected: []sql.Row{
1111+
{"c2", "varchar(200)", "YES", "", nil, ""},
1112+
{"c3", "enum('one','two')", "YES", "", nil, ""},
1113+
},
1114+
},
1115+
{
1116+
Query: "alter table t add column new3 int;",
1117+
Expected: []sql.Row{{types.NewOkResult(0)}},
1118+
},
1119+
{
1120+
Query: `insert into t values ('two', 'two', -2);`,
1121+
Expected: []sql.Row{{types.NewOkResult(1)}},
1122+
},
1123+
{
1124+
Query: "describe t;",
1125+
Expected: []sql.Row{
1126+
{"c2", "varchar(200)", "YES", "", nil, ""},
1127+
{"c3", "enum('one','two')", "YES", "", nil, ""},
1128+
{"new3", "int", "YES", "", nil, ""},
1129+
},
1130+
},
1131+
{
1132+
Query: "select * from t;",
1133+
Expected: []sql.Row{{"one", nil, nil}, {"two", "two", -2}},
1134+
},
1135+
},
1136+
},
1137+
{
1138+
Name: "preserve enums through alter statements",
1139+
SetUpScript: []string{
1140+
"create table t (i int primary key, e enum('a', 'b', 'c'));",
1141+
"insert ignore into t values (0, 'error');",
1142+
"insert into t values (1, 'a');",
1143+
"insert into t values (2, 'b');",
1144+
"insert into t values (3, 'c');",
1145+
},
1146+
Assertions: []ScriptTestAssertion{
1147+
{
1148+
Query: "select i, e, e + 0 from t;",
1149+
Expected: []sql.Row{
1150+
{0, "", float64(0)},
1151+
{1, "a", float64(1)},
1152+
{2, "b", float64(2)},
1153+
{3, "c", float64(3)},
1154+
},
1155+
},
1156+
{
1157+
Query: "alter table t modify column e enum('c', 'a', 'b');",
1158+
Expected: []sql.Row{
1159+
{types.NewOkResult(0)},
1160+
},
1161+
},
1162+
{
1163+
Query: "select i, e, e + 0 from t;",
1164+
Expected: []sql.Row{
1165+
{0, "", float64(0)},
1166+
{1, "a", float64(2)},
1167+
{2, "b", float64(3)},
1168+
{3, "c", float64(1)},
1169+
},
1170+
},
1171+
{
1172+
Query: "alter table t modify column e enum('asdf', 'a', 'b', 'c');",
1173+
Expected: []sql.Row{
1174+
{types.NewOkResult(0)},
1175+
},
1176+
},
1177+
{
1178+
Query: "select i, e, e + 0 from t;",
1179+
Expected: []sql.Row{
1180+
{0, "", float64(0)},
1181+
{1, "a", float64(2)},
1182+
{2, "b", float64(3)},
1183+
{3, "c", float64(4)},
1184+
},
1185+
},
1186+
{
1187+
Query: "alter table t modify column e enum('asdf', 'a', 'b', 'c', 'd');",
1188+
Expected: []sql.Row{
1189+
{types.NewOkResult(0)},
1190+
},
1191+
},
1192+
{
1193+
Query: "select i, e, e + 0 from t;",
1194+
Expected: []sql.Row{
1195+
{0, "", float64(0)},
1196+
{1, "a", float64(2)},
1197+
{2, "b", float64(3)},
1198+
{3, "c", float64(4)},
1199+
},
1200+
},
1201+
{
1202+
Query: "alter table t modify column e enum('a', 'b', 'c');",
1203+
Expected: []sql.Row{
1204+
{types.NewOkResult(0)},
1205+
},
1206+
},
1207+
{
1208+
Query: "select i, e, e + 0 from t;",
1209+
Expected: []sql.Row{
1210+
{0, "", float64(0)},
1211+
{1, "a", float64(1)},
1212+
{2, "b", float64(2)},
1213+
{3, "c", float64(3)},
1214+
},
1215+
},
1216+
{
1217+
Query: "alter table t modify column e enum('abc');",
1218+
ExpectedErr: types.ErrDataTruncatedForColumn,
1219+
},
1220+
},
1221+
},
1222+
1223+
// Set tests
1224+
{
1225+
Name: "modify set column",
1226+
SetUpScript: []string{
1227+
"create table t (i int primary key, s set('a', 'b', 'c'));",
1228+
"insert ignore into t values (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7);",
1229+
},
1230+
Assertions: []ScriptTestAssertion{
1231+
{
1232+
Query: "select i, s + 0, s from t;",
1233+
Expected: []sql.Row{
1234+
{0, float64(0), ""},
1235+
{1, float64(1), "a"},
1236+
{2, float64(2), "b"},
1237+
{3, float64(3), "a,b"},
1238+
{4, float64(4), "c"},
1239+
{5, float64(5), "a,c"},
1240+
{6, float64(6), "b,c"},
1241+
{7, float64(7), "a,b,c"},
1242+
},
1243+
},
1244+
{
1245+
Query: "alter table t modify column s set('a', 'b', 'c', 'd');",
1246+
Expected: []sql.Row{
1247+
{types.NewOkResult(0)},
1248+
},
1249+
},
1250+
{
1251+
Query: "select i, s + 0, s from t;",
1252+
Expected: []sql.Row{
1253+
{0, float64(0), ""},
1254+
{1, float64(1), "a"},
1255+
{2, float64(2), "b"},
1256+
{3, float64(3), "a,b"},
1257+
{4, float64(4), "c"},
1258+
{5, float64(5), "a,c"},
1259+
{6, float64(6), "b,c"},
1260+
{7, float64(7), "a,b,c"},
1261+
},
1262+
},
1263+
{
1264+
Skip: true,
1265+
Query: "alter table t modify column s set('c', 'b', 'a');",
1266+
Expected: []sql.Row{
1267+
{types.NewOkResult(8)}, // We currently return 0 RowsAffected
1268+
},
1269+
},
1270+
{
1271+
Skip: true,
1272+
Query: "select i, s + 0, s from t;",
1273+
Expected: []sql.Row{
1274+
{0, 0, ""},
1275+
{1, 2, "a"},
1276+
{2, 4, "b"},
1277+
{3, 6, "a,b"},
1278+
{4, 1, "c"},
1279+
{5, 3, "c,a"},
1280+
{6, 5, "c,b"},
1281+
{7, 7, "c,a,b"},
1282+
},
1283+
},
1284+
{
1285+
Skip: true,
1286+
Query: "alter table t modify column s set('a');",
1287+
ExpectedErrStr: "Data truncated for column", // We currently throw value 2 is not valid for this set
1288+
},
1289+
},
1290+
},
10651291
}
10661292

10671293
var RenameTableScripts = []ScriptTest{

0 commit comments

Comments
 (0)