/**
* Perform a schema change to a mutated version of the current table (80%) or
* to a new table entirely (20%, drops and adds the new table).
*/
private Pair<VoltTable,TableHelper.ViewRep> catalogChange(VoltTable t1, boolean newTable, TableHelper.ViewRep view) throws Exception {
CatalogBuilder builder = new CatalogBuilder();
VoltTable t2 = null;
String currentName = t1 == null ? "B" : TableHelper.getTableName(t1);
String newName = currentName;
// add an empty table with the schema version number in it
VoltTable versionT = TableHelper.quickTable(String.format("V%s (BIGINT)", schemaVersionNo + 1));
if (newTable) {
newName = currentName.equals("A") ? "B" : "A";
t2 = TableHelper.getTotallyRandomTable(newName, rand, false);
}
else {
t2 = TableHelper.mutateTable(t1, true, rand);
}
log.info(_F("New Schema:\n%s", TableHelper.ddlForTable(t2)));
// handle views
if (view == null) {
view = TableHelper.ViewRep.viewRepForTable("MV", t2, rand);
}
else {
if (!view.compatibleWithTable(t2)) {
view = null;
}
}
if (view != null) {
log.info(_F("New View:\n%s", view.ddlForView()));
}
else {
log.info("New View: NULL");
}
builder.addLiteralSchema(TableHelper.ddlForTable(t2));
if (view != null) {
builder.addLiteralSchema(view.ddlForView());
}
builder.addLiteralSchema(TableHelper.ddlForTable(versionT));
// make tables name A partitioned and tables named B replicated
if (newName.equalsIgnoreCase("A")) {
int pkeyIndex = TableHelper.getBigintPrimaryKeyIndexIfExists(t2);
builder.addPartitionInfo(newName, t2.getColumnName(pkeyIndex));
builder.addProcedures(VerifySchemaChangedA.class);
}
else {
builder.addProcedures(VerifySchemaChangedB.class);
}
byte[] catalogData = builder.compileToBytes();
assert(catalogData != null);
long count = tupleCount(t1);
long start = System.nanoTime();