this.stats = new WorkloadStatistics(this.stats_catalog_db);
for (Table catalog_tbl : this.stats_catalog_db.getTables()) {
this.stats.getTableStatistics(catalog_tbl).preprocess(this.stats_catalog_db);
} // FOR
}
final Table catalog_tbl = CatalogUtil.getCatalogTable(stats_catalog_db, voltTable);
if (catalog_tbl == null) {
LOG.fatal("Failed to find corresponding table catalog object for parameter " + ctr + " in " + catalog_proc);
String msg = "Table Columns: ";
for (int i = 0, cnt = voltTable.getColumnCount(); i < cnt; i++) {
msg += voltTable.getColumnName(i) + " ";
}
LOG.fatal(msg);
return;
}
final String table_key = CatalogKey.createKey(catalog_tbl);
TableStatistics table_stats = this.stats.getTableStatistics(table_key);
// Temporary Loader Procedure
TransactionTrace loader_xact = new TransactionTrace(xact_id, catalog_proc, new Object[0]) {
/**
* We need this wrapper so that when CatalogUtil tries to figure out what
* the index of partitioning parameter we can just use the column index of partitioning
* attribute of the table that we are inserting into
*/
private final Procedure proc = new Procedure() {
@Override
public int getPartitionparameter() {
return (catalog_tbl.getPartitioncolumn().getIndex());
}
@Override
public Catalog getCatalog() {
return (catalog);
}
};
@Override
public Procedure getCatalogItem(Database catalog_db) {
return (proc);
}
}; // Nasty...
// Use a temporary query trace to wrap the "insert" of each tuple
Statement catalog_stmt = this.stats_load_stmts.get(table_key);
if (catalog_stmt == null) {
catalog_stmt = catalog_proc.getStatements().add("INSERT_" + catalog_tbl.getName());
catalog_stmt.setQuerytype(QueryType.INSERT.getValue());
this.stats_load_stmts.put(table_key, catalog_stmt);
// TERRIBLE HACK!
// 2011-01-25 :: Why do I need to do this??
// String stmt_key = CatalogKey.createKey(catalog_stmt);
// CatalogUtil.CACHE_STATEMENT_COLUMNS_KEYS.put(stmt_key, new java.util.HashSet<String>());
// CatalogUtil.CACHE_STATEMENT_COLUMNS_KEYS.get(stmt_key).add(table_key);
}
QueryTrace loader_query = new QueryTrace(catalog_stmt, new Object[0], 0);
loader_xact.addQuery(loader_query);
// Gather column types
int num_columns = voltTable.getColumnCount();
VoltType col_types[] = new VoltType[num_columns];
for (int i = 0; i < num_columns; i++) {
Column catalog_col = catalog_tbl.getColumns().get(i);
col_types[i] = VoltType.get((byte)catalog_col.getType());
} // FOR
loader_query.params = new Object[num_columns];
int num_tuples = voltTable.getRowCount();
try {
LOG.info("Processing " + num_tuples + " (sample=10) tuples for statistics on " + catalog_tbl.getName());
boolean show_progress = (num_tuples > 25000);
for (int i = 0; i < num_tuples; i += 10) {
if (i >= num_tuples) break;
VoltTableRow tuple = voltTable.fetchRow(i);
for (int j = 0; j < num_columns; j++) {
loader_query.params[j] = tuple.get(j, col_types[j]);
} // FOR
table_stats.process(stats_catalog_db, loader_xact);
if (show_progress && i > 0 && i % 10000 == 0) LOG.info(i + " tuples");
// if (i > 25000) break;
} // FOR
LOG.info("Processing finished for " + catalog_tbl.getName());
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
} // FOR