-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathDorisAlterTableGenerator.java
More file actions
50 lines (44 loc) · 1.68 KB
/
DorisAlterTableGenerator.java
File metadata and controls
50 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package sqlancer.doris.gen;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.doris.DorisProvider.DorisGlobalState;
import sqlancer.doris.DorisSchema.DorisCompositeDataType;
import sqlancer.doris.DorisSchema.DorisTable;
public final class DorisAlterTableGenerator {
private DorisAlterTableGenerator() {
}
enum Action {
ADD_COLUMN, ALTER_COLUMN, DROP_COLUMN
}
public static SQLQueryAdapter getQuery(DorisGlobalState globalState) {
ExpectedErrors errors = new ExpectedErrors();
StringBuilder sb = new StringBuilder("ALTER TABLE ");
DorisTable table = globalState.getSchema().getRandomTable(t -> !t.isView());
sb.append(table.getName());
sb.append(" ");
Action action = Randomly.fromOptions(Action.values());
switch (action) {
case ADD_COLUMN:
sb.append("ADD COLUMN ");
String columnName = table.getFreeColumnName();
sb.append(columnName);
sb.append(" ");
sb.append(DorisCompositeDataType.getRandomWithoutNull().toString());
break;
case ALTER_COLUMN:
sb.append("MODIFY COLUMN ");
sb.append(table.getRandomColumn().getName());
sb.append(" ");
sb.append(DorisCompositeDataType.getRandomWithoutNull().toString());
break;
case DROP_COLUMN:
sb.append("DROP COLUMN ");
sb.append(table.getRandomColumn().getName());
break;
default:
throw new AssertionError(action);
}
return new SQLQueryAdapter(sb.toString(), errors, true);
}
}