Table table = tables.get(tableName);
if (table == null) {
String msg = String.format("@UpdateApplicationCatalog was checking to see if table %s was empty, " +
"presumably as part of a schema change, and it failed to find the table " +
"in the current catalog context.", tableName);
throw new SpecifiedException(ClientResponse.UNEXPECTED_FAILURE, msg);
}
tableIds[i++] = table.getRelativeIndex();
}
// get the table stats for these tables from the EE
final VoltTable[] s1 =
context.getSiteProcedureConnection().getStats(StatsSelector.TABLE,
tableIds,
false,
getTransactionTime().getTime());
if ((s1 == null) || (s1.length == 0)) {
String tableNames = StringUtils.join(tablesThatMustBeEmpty, ", ");
String msg = String.format("@UpdateApplicationCatalog was checking to see if tables (%s) were empty ," +
"presumably as part of a schema change, but failed to get the row counts " +
"from the native storage engine.", tableNames);
throw new SpecifiedException(ClientResponse.UNEXPECTED_FAILURE, msg);
}
VoltTable stats = s1[0];
SortedSet<String> nonEmptyTables = new TreeSet<String>();
// find all empty tables
while (stats.advanceRow()) {
long tupleCount = stats.getLong("TUPLE_COUNT");
String tableName = stats.getString("TABLE_NAME");
if (tupleCount > 0) {
nonEmptyTables.add(tableName);
}
}
// return an error containing the names of all non-empty tables
// via the propagated reasons why each needs to be empty
if (!nonEmptyTables.isEmpty()) {
String msg = "Unable to make requested schema change:\n";
for (i = 0; i < tablesThatMustBeEmpty.length; ++i) {
if (nonEmptyTables.contains(tablesThatMustBeEmpty[i])) {
msg += reasonsForEmptyTables[i] + "\n";
}
}
throw new SpecifiedException(ClientResponse.GRACEFUL_FAILURE, msg);
}
}