*/
public void testPartitionEstimator() throws Exception {
Integer base_partition = 1;
Database clone_db = CatalogCloner.cloneDatabase(catalog_db);
CatalogContext clone_catalogContext = new CatalogContext(clone_db.getCatalog());
PartitionEstimator p_estimator = new PartitionEstimator(clone_catalogContext);
info = this.generateInfo(clone_catalogContext);
Table catalog_tbl = this.getTable(clone_db, TM1Constants.TABLENAME_SUBSCRIBER);
Column target_col = this.getColumn(catalog_tbl, "S_ID");
Collection<VerticalPartitionColumn> candidates = VerticalPartitionerUtil.generateCandidates(target_col, info.stats);
assertNotNull(candidates);
assertFalse(candidates.isEmpty());
VerticalPartitionColumn vpc = CollectionUtil.first(candidates);
assertNotNull(vpc);
assertFalse(vpc.isUpdateApplied());
// Get the original partitions for the queries before we apply the optimizations
Map<Statement, Object[]> stmt_params = new HashMap<Statement, Object[]>();
for (Statement catalog_stmt : vpc.getOptimizedQueries()) {
// We first need to generate random input parameters
Object params[] = new Object[catalog_stmt.getParameters().size()];
for (int i = 0; i < params.length; i++) {
StmtParameter catalog_param = catalog_stmt.getParameters().get(i);
VoltType vtype = VoltType.get(catalog_param.getJavatype());
params[i] = VoltTypeUtil.getRandomValue(vtype);
} // FOR
stmt_params.put(catalog_stmt, params);
// Then get the list of partitions that it will access
// This should always be *all* partitions
PartitionSet partitions = new PartitionSet();
p_estimator.getAllPartitions(partitions, catalog_stmt, params, base_partition);
assertNotNull(partitions);
assertEquals(CatalogUtil.getNumberOfPartitions(clone_db), partitions.size());
} // FOR
// Now apply the optimized queries
// The number of partitions that our Statements touch should be reduced to one
vpc.applyUpdate();
assert(vpc.isUpdateApplied());
for (Statement catalog_stmt : vpc.getOptimizedQueries()) {
Object params[] = stmt_params.get(catalog_stmt);
assertNotNull(params);
PartitionSet partitions = new PartitionSet();
p_estimator.getAllPartitions(partitions, catalog_stmt, params, base_partition);
assertNotNull(partitions);
assertEquals(1, partitions.size());
} // FOR
}