*/
@Test
public void testInvalidateCache() throws Exception {
Catalog new_catalog = new Catalog();
new_catalog.execute(catalogContext.catalog.serialize());
CatalogContext new_catalogContext = new CatalogContext(new_catalog);
final Table new_table = new_catalogContext.database.getTables().get(TPCCConstants.TABLENAME_WAREHOUSE);
assertNotNull(new_table);
new_table.setPartitioncolumn(new Column() {
@SuppressWarnings("unchecked")
@Override
public <T extends CatalogType> T getParent() {
return ((T)new_table);
}
});
PartitionEstimator p_estimator = new PartitionEstimator(catalogContext, hasher);
Procedure catalog_proc = this.getProcedure(neworder.class);
Statement catalog_stmt = catalog_proc.getStatements().get("getWarehouseTaxRate");
assertNotNull(catalog_stmt);
// First calculate the partitions for the query using the original catalog
// We should get back exactly one partition id (base_partition)
Object params[] = new Object[] { new Long(BASE_PARTITION) };
for (int i = 0; i < 10000; i++) {
String debug = String.format("Attempt #%05d", i);
this.partitions.clear();
p_estimator.getAllPartitions(this.partitions, catalog_stmt, params, BASE_PARTITION);
assertEquals(debug + " -> " + this.partitions.toString(), 1, this.partitions.size());
assertEquals(debug, BASE_PARTITION, CollectionUtil.first(this.partitions).intValue());
assertFalse(debug, this.partitions.contains(HStoreConstants.NULL_PARTITION_ID));
} // FOR
// Then reset the catalog in p_estimator and run the estimation again
// The new catalog has a different partition column for WAREHOUSE, so we should get
// back all the partitions
p_estimator.initCatalog(new_catalogContext);
catalog_proc = new_catalogContext.database.getProcedures().get(catalog_proc.getName());
catalog_stmt = catalog_proc.getStatements().get("getWarehouseTaxRate");
partitions.clear();
p_estimator.getAllPartitions(partitions, catalog_stmt, params, BASE_PARTITION);
PartitionSet all_partitions = new_catalogContext.getAllPartitionIds();
assertNotNull(partitions);
assertEquals(all_partitions.size(), partitions.size());
assertFalse(partitions.contains(HStoreConstants.NULL_PARTITION_ID));
}