Skip to content

Commit

Permalink
MONDRIAN: Fixed 1767798 and an issue with grouping of batches and opt…
Browse files Browse the repository at this point in the history
…imized the loop. Also removed the discarding of exception.

[git-p4: depot-paths = "//open/mondrian/": change = 9719]
  • Loading branch information
thiyagu committed Aug 7, 2007
1 parent 289313e commit 2426e59
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 22 deletions.
7 changes: 2 additions & 5 deletions src/main/mondrian/rolap/FastBatchingCellReader.java
Expand Up @@ -251,11 +251,7 @@ List<CompositeBatch> groupBatches(List<Batch> batchList) {
Map<BatchKey, CompositeBatch> batchGroups =
new HashMap<BatchKey, CompositeBatch>();
for (int i = 0; i < batchList.size(); i++) {
for (int j = 0; j < batchList.size() && i < batchList.size();) {
if (i == j) {
j++;
continue;
}
for (int j = i + 1; j < batchList.size() && i < batchList.size();) {
FastBatchingCellReader.Batch iBatch = batchList.get(i);
FastBatchingCellReader.Batch jBatch = batchList.get(j);
if (iBatch.canBatch(jBatch)) {
Expand All @@ -265,6 +261,7 @@ List<CompositeBatch> groupBatches(List<Batch> batchList) {
batchList.set(i, jBatch);
batchList.remove(j);
addToCompositeBatch(batchGroups, jBatch, iBatch);
j = i + 1;
} else {
j++;
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/mondrian/rolap/agg/Segment.java
Expand Up @@ -134,6 +134,7 @@ synchronized void setData(

this.data = data;
this.state = State.Ready;

notifyAll();
}

Expand Down Expand Up @@ -174,7 +175,7 @@ private void makeDescription(StringBuilder buf, boolean values) {
buf.append(columns[i].getExpression().getGenericExpression());
final Aggregation.Axis axis = axes[i];
axis.getPredicate().describe(buf);
if (values) {
if (values && isReady()) {
Object[] keys = axis.getKeys();
buf.append(", values={");
for (int j = 0; j < keys.length; j++) {
Expand Down Expand Up @@ -309,7 +310,7 @@ private boolean isExcluded(Object[] keys) {
* already loaded, returns immediately.
*/
public synchronized void waitUntilLoaded() {
if (!isReady()) {
if (isLoading()) {
try {
LOGGER.debug("Waiting on " + printSegmentHeaderInfo(","));
wait();
Expand All @@ -327,6 +328,10 @@ public synchronized void waitUntilLoaded() {
}
}

private boolean isLoading() {
return state == State.Loading;
}

/**
* Prints the state of this <code>Segment</code>, including constraints
* and values. Blocks the current thread until the segment is loaded.
Expand Down
2 changes: 0 additions & 2 deletions src/main/mondrian/rolap/agg/SegmentLoader.java
Expand Up @@ -114,8 +114,6 @@ public void load(

} catch (SQLException e) {
throw stmt.handle(e);
} catch (RuntimeException e) {
throw e;
} finally {
if (stmt != null) {
stmt.close();
Expand Down
111 changes: 98 additions & 13 deletions testsrc/main/mondrian/rolap/FastBatchingCellReaderTest.java
Expand Up @@ -191,6 +191,99 @@ boolean canBatch(FastBatchingCellReader.Batch batch) {
assertTrue(groupedBatches.get(1).summaryBatches.contains(group2Agg1));
}

public void testGroupBatchesForTwoSetOfGroupableBatches() {
String[] fieldValuesStoreType = {"Deluxe Supermarket", "Gourmet Supermarket", "HeadQuarters",
"Mid-Size Grocery", "Small Grocery", "Supermarket"};
String fieldStoreType = "store_type";
String tableStore = "store";

String[] fieldValuesWarehouseCountry = {"Canada", "Mexico", "USA"};
String fieldWarehouseCountry = "warehouse_country";
String tableWarehouse = "warehouse";

FastBatchingCellReader fbcr = new FastBatchingCellReader(null);
FastBatchingCellReader.Batch batch1RollupOnGender =
createBatch(fbcr,
new String[]{tableTime, tableStore, tableProductClass},
new String[]{fieldYear, fieldStoreType, fieldProductFamily},
new String[][]{fieldValuesYear, fieldValuesStoreType, fieldValuesProductFamily},
cubeNameSales,
measureUnitSales);

FastBatchingCellReader.Batch batch1RollupOnGenderAndProductDepartment =
createBatch(fbcr, new String[]{tableTime, tableProductClass},
new String[]{fieldYear, fieldProductFamily},
new String[][]{fieldValuesYear, fieldValuesProductFamily},
cubeNameSales, measureUnitSales);

FastBatchingCellReader.Batch batch1RollupOnStoreTypeAndProductDepartment =
createBatch(fbcr,
new String[]{tableTime, tableCustomer},
new String[]{fieldYear, fieldGender},
new String[][]{fieldValuesYear, fieldValuesGender},
cubeNameSales, measureUnitSales);

FastBatchingCellReader.Batch batch1Detailed =
createBatch(fbcr,
new String[]{tableTime, tableStore,
tableProductClass, tableCustomer},
new String[]{fieldYear, fieldStoreType, fieldProductFamily,
fieldGender},
new String[][]{fieldValuesYear, fieldValuesStoreType,
fieldValuesProductFamily,
fieldValuesGender},
cubeNameSales,
measureUnitSales);


String warehouseCube = "Warehouse";
String measure2 = "[Measures].[Warehouse Sales]";
FastBatchingCellReader.Batch batch2RollupOnStoreType =
createBatch(fbcr,
new String[]{tableWarehouse, tableTime, tableProductClass
}, new String[]{fieldWarehouseCountry, fieldYear,
fieldProductFamily},
new String[][]{fieldValuesWarehouseCountry, fieldValuesYear,
fieldValuesProductFamily}, warehouseCube,
measure2);

FastBatchingCellReader.Batch batch2RollupOnStoreTypeAndWareHouseCountry =
createBatch(fbcr, new String[]{tableTime,tableProductClass},
new String[]{fieldYear,fieldProductFamily},
new String[][]{fieldValuesYear,fieldValuesProductFamily},
warehouseCube, measure2);

FastBatchingCellReader.Batch batch2RollupOnProductFamilyAndWareHouseCountry =
createBatch(fbcr,
new String[]{tableTime, tableStore},
new String[]{fieldYear, fieldStoreType},
new String[][]{fieldValuesYear, fieldValuesStoreType},
warehouseCube, measure2);

FastBatchingCellReader.Batch batch2Detailed =
createBatch(fbcr,
new String[]{tableWarehouse, tableTime, tableStore, tableProductClass},
new String[]{fieldWarehouseCountry, fieldYear, fieldStoreType, fieldProductFamily},
new String[][]{fieldValuesWarehouseCountry, fieldValuesYear, fieldValuesStoreType,
fieldValuesProductFamily},
warehouseCube,
measure2);

List<FastBatchingCellReader.Batch> batchList = new ArrayList<FastBatchingCellReader.Batch>();

batchList.add(batch1RollupOnGender);
batchList.add(batch2RollupOnStoreType);
batchList.add(batch2RollupOnStoreTypeAndWareHouseCountry);
batchList.add(batch2RollupOnProductFamilyAndWareHouseCountry);
batchList.add(batch1RollupOnGenderAndProductDepartment);
batchList.add(batch1RollupOnStoreTypeAndProductDepartment);
batchList.add(batch2Detailed);
batchList.add(batch1Detailed);
List<FastBatchingCellReader.CompositeBatch> groupedBatches =
fbcr.groupBatches(batchList);
assertEquals(2, groupedBatches.size());
}

public void testAddToCompositeBatchForBothBatchesNotPartOfCompositeBatch() {
FastBatchingCellReader fbcr = new FastBatchingCellReader(null);
FastBatchingCellReader.Batch batch1 = fbcr.new Batch(
Expand Down Expand Up @@ -594,6 +687,9 @@ public void load(
RolapAggregationManager.PinSet pinnedSegments)
{
groupingSets.addAll(sets);
for (GroupingSet groupingSet : sets) {
groupingSet.setSegmentsFailed();
}
}
};
}
Expand All @@ -603,20 +699,9 @@ public void load(
compositeBatch.loadAggregation();

assertEquals(2, groupingSets.size());
GroupingSetsCollector detailedCollector =
new GroupingSetsCollector(true);
detailedBatch.loadAggregation(detailedCollector);
List<GroupingSet> baseGroupingSet =
detailedCollector.getGroupingSets();
GroupingSetsCollector summaryCollector =
new GroupingSetsCollector(true);
summaryBatch.loadAggregation(summaryCollector);
List<GroupingSet> groupingSet =
summaryCollector.getGroupingSets();

assertEquals(baseGroupingSet.get(0).getLevelBitKey(),
assertEquals(detailedBatch.constrainedColumnsBitKey,
groupingSets.get(0).getLevelBitKey());
assertEquals(groupingSet.get(0).getLevelBitKey(),
assertEquals(summaryBatch.constrainedColumnsBitKey,
groupingSets.get(1).getLevelBitKey());

}
Expand Down

0 comments on commit 2426e59

Please sign in to comment.