Skip to content

Commit

Permalink
MONDRIAN: Fix for bug #1907809 - IndexOutOfBoundException when filter…
Browse files Browse the repository at this point in the history
…ing aggregation list

[git-p4: depot-paths = "//open/mondrian/": change = 10666]
  • Loading branch information
Ajit Joglekar committed Mar 6, 2008
1 parent abe5f7b commit 71d47d3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 38 deletions.
4 changes: 4 additions & 0 deletions src/main/mondrian/olap/fun/AbstractAggregateFunDef.java
Expand Up @@ -127,6 +127,10 @@ private static List processUnrelatedDimensions(
Evaluator evaluator)
{

if (tuplesForAggregation.size() == 0) {
return tuplesForAggregation;
}

RolapMember measure = (RolapMember) evaluator.getMembers()[0];

if (measure.isCalculated()) {
Expand Down
101 changes: 63 additions & 38 deletions testsrc/main/mondrian/test/BasicQueryTest.java
Expand Up @@ -39,6 +39,8 @@ public class BasicQueryTest extends FoodMartTestCase {
"Axis #1:\n" +
"Axis #2:\n");

private MondrianProperties props = MondrianProperties.instance();

public BasicQueryTest() {
super();
}
Expand Down Expand Up @@ -2645,7 +2647,7 @@ public void testBug769114() {
* the validation time was <code>O(2 ^ depth)</code>.)
*/
public void _testBug793616() {
if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
if (props.TestExpDependencies.get() > 0) {
// Don't run this test if dependency-checking is enabled.
// Dependency checking will hugely slow down evaluation, and give
// the false impression that the validation performance bug has
Expand Down Expand Up @@ -2767,7 +2769,7 @@ public void _testBug793616() {
public void testCatalogHierarchyBasedOnView() {
// Don't run this test if aggregates are enabled: two levels mapped to
// the "gender" column confuse the agg engine.
if (MondrianProperties.instance().ReadAggregates.get()) {
if (props.ReadAggregates.get()) {
return;
}
TestContext testContext = TestContext.createSubstitutingCube(
Expand Down Expand Up @@ -2812,7 +2814,7 @@ public void testCatalogHierarchyBasedOnView() {
public void testCatalogHierarchyBasedOnView2() {
// Don't run this test if aggregates are enabled: two levels mapped to
// the "gender" column confuse the agg engine.
if (MondrianProperties.instance().ReadAggregates.get()) {
if (props.ReadAggregates.get()) {
return;
}
if (getTestContext().getDialect().allowsFromQuery()) {
Expand Down Expand Up @@ -2941,12 +2943,11 @@ public void testCountDistinct() {
* then no aggregate tables is be read in any event.
*/
public void testCountDistinctAgg() {
final MondrianProperties properties = MondrianProperties.instance();
boolean use_agg_orig = properties.UseAggregates.get();
boolean do_caching_orig = properties.DisableCaching.get();
boolean use_agg_orig = props.UseAggregates.get();
boolean do_caching_orig = props.DisableCaching.get();

// turn off caching
properties.DisableCaching.setString("true");
props.DisableCaching.setString("true");

assertQueryReturns(
"select {[Measures].[Unit Sales], [Measures].[Customer Count]} on rows,\n" +
Expand All @@ -2963,9 +2964,9 @@ public void testCountDistinctAgg() {
"Row #1: 1,396\n"));

if (use_agg_orig) {
properties.UseAggregates.setString("false");
props.UseAggregates.setString("false");
} else {
properties.UseAggregates.setString("true");
props.UseAggregates.setString("true");
}

assertQueryReturns(
Expand All @@ -2983,14 +2984,14 @@ public void testCountDistinctAgg() {
"Row #1: 1,396\n"));

if (use_agg_orig) {
properties.UseAggregates.setString("true");
props.UseAggregates.setString("true");
} else {
properties.UseAggregates.setString("false");
props.UseAggregates.setString("false");
}
if (do_caching_orig) {
properties.DisableCaching.setString("true");
props.DisableCaching.setString("true");
} else {
properties.DisableCaching.setString("false");
props.DisableCaching.setString("false");
}
}

Expand Down Expand Up @@ -3133,17 +3134,16 @@ public void testSlicerOverride() {
}

public void testMembersOfLargeDimensionTheHardWay() {
final MondrianProperties properties = MondrianProperties.instance();

// Avoid this test if memory is scarce.
if (Bug.avoidMemoryOverflow(TestContext.instance().getDialect())) {
return;
}

int old = properties.LargeDimensionThreshold.get();
int old = props.LargeDimensionThreshold.get();
try {
// prevent a CacheMemberReader from kicking in
MondrianProperties.instance().LargeDimensionThreshold.set(1);
props.LargeDimensionThreshold.set(1);
final Connection connection =
TestContext.instance().getFoodMartConnection();
String queryString =
Expand All @@ -3154,7 +3154,7 @@ public void testMembersOfLargeDimensionTheHardWay() {
Result result = connection.execute(query);
assertEquals(10407, result.getAxes()[1].getPositions().size());
} finally {
MondrianProperties.instance().LargeDimensionThreshold.set(old);
props.LargeDimensionThreshold.set(old);
}
}

Expand Down Expand Up @@ -4540,7 +4540,7 @@ public void testFilteredCrossJoin() {
* we can push down evaluation to SQL.
*/
public void testNonEmptyCrossJoin() {
if (!MondrianProperties.instance().EnableNativeCrossJoin.get()) {
if (!props.EnableNativeCrossJoin.get()) {
// If we try to evaluate the crossjoin in memory we run out of
// memory.
return;
Expand Down Expand Up @@ -5282,14 +5282,11 @@ public void testInvalidMembersInQuery() {
"MDX object '[Time].[1997].[QTOO]' not found in cube 'Sales'");

// Now set property
final MondrianProperties properties = MondrianProperties.instance();

boolean savedInvalidProp =
properties.IgnoreInvalidMembersDuringQuery.get();
String savedAlertProp =
properties.AlertNativeEvaluationUnsupported.get();
boolean savedInvalidProp = props.IgnoreInvalidMembersDuringQuery.get();
String savedAlertProp = props.AlertNativeEvaluationUnsupported.get();
try {
properties.IgnoreInvalidMembersDuringQuery.set(true);
props.IgnoreInvalidMembersDuringQuery.set(true);
assertQueryReturns(
mdx,
fold(
Expand All @@ -5303,7 +5300,7 @@ public void testInvalidMembersInQuery() {

// Verify that invalid members in query do NOT prevent
// usage of native NECJ (LER-5165).
properties.AlertNativeEvaluationUnsupported.set("ERROR");
props.AlertNativeEvaluationUnsupported.set("ERROR");
assertQueryReturns(
mdx2,
fold(
Expand All @@ -5319,16 +5316,15 @@ public void testInvalidMembersInQuery() {
"Row #1: 19,287\n" +
"Row #2: 30,114\n"));
} finally {
properties.IgnoreInvalidMembersDuringQuery.set(savedInvalidProp);
properties.AlertNativeEvaluationUnsupported.set(savedAlertProp);
props.IgnoreInvalidMembersDuringQuery.set(savedInvalidProp);
props.AlertNativeEvaluationUnsupported.set(savedAlertProp);
}
}

public void testMemberOrdinalCaching() {
final MondrianProperties properties = MondrianProperties.instance();

boolean saved = properties.CompareSiblingsByOrderKey.get();
properties.CompareSiblingsByOrderKey.set(true);
boolean saved = props.CompareSiblingsByOrderKey.get();
props.CompareSiblingsByOrderKey.set(true);
Connection conn = null;
try {
// Use a fresh connection to make sure bad member ordinals haven't
Expand All @@ -5337,7 +5333,7 @@ public void testMemberOrdinalCaching() {
TestContext context = getTestContext(conn);
tryMemberOrdinalCaching(context);
} finally {
properties.CompareSiblingsByOrderKey.set(saved);
props.CompareSiblingsByOrderKey.set(saved);
if (conn != null) {
conn.close();
}
Expand Down Expand Up @@ -5489,15 +5485,15 @@ public void testQueryTimeout()
" {[Product].members} ON ROWS\n" +
"FROM [Sales]";
Throwable throwable = null;
int origTimeout = MondrianProperties.instance().QueryTimeout.get();
int origTimeout = props.QueryTimeout.get();
try {
MondrianProperties.instance().QueryTimeout.set(2);
props.QueryTimeout.set(2);
tc.executeQuery(query);
} catch (Throwable ex) {
throwable = ex;
} finally {
// reset the timeout back to the original value
MondrianProperties.instance().QueryTimeout.set(origTimeout);
props.QueryTimeout.set(origTimeout);
}
TestContext.checkThrowable(
throwable, "Query timeout of 2 seconds reached");
Expand Down Expand Up @@ -5652,9 +5648,9 @@ public void testQueryIterationLimit()
"on columns from [Sales]";

Throwable throwable = null;
int origLimit = MondrianProperties.instance().IterationLimit.get();
int origLimit = props.IterationLimit.get();
try {
MondrianProperties.instance().IterationLimit.set(11);
props.IterationLimit.set(11);
Connection connection = getConnection();
Query query = connection.parseQuery(queryString);
query.setResultStyle(ResultStyle.LIST);
Expand All @@ -5663,7 +5659,7 @@ public void testQueryIterationLimit()
throwable = ex;
} finally {
// reset the timeout back to the original value
MondrianProperties.instance().IterationLimit.set(origLimit);
props.IterationLimit.set(origLimit);
}

TestContext.checkThrowable(
Expand Down Expand Up @@ -5767,7 +5763,7 @@ public void testDefaultMeasureInCubeForCaseSensitivity() {
"from DefaultMeasureTesting where [measures].[Store Invoice]";
String queryWithDefaultMeasureFilter = "select store.members on 0 " +
"from DefaultMeasureTesting where [measures].[Supply Time]";
if (MondrianProperties.instance().CaseSensitive.get()) {
if (props.CaseSensitive.get()) {
assertQueriesReturnSimilarResults(queryWithoutFilter,
queryWithFirstMeasure, testContext);
} else {
Expand Down Expand Up @@ -6218,6 +6214,35 @@ public void testIifWithTuplesOfUnequalSizesAndOrder() {
"Row #2: 135,215\n"));
}

public void testEmptyAggregationListDueToFilterDoesNotThrowException() {
boolean ignoreMeasureForNonJoiningDimension =
props.IgnoreMeasureForNonJoiningDimension.get();
props.IgnoreMeasureForNonJoiningDimension.set(true);
try {
assertQueryReturns(
"WITH \n" +
"MEMBER [GENDER].[AGG] " +
"AS 'AGGREGATE(FILTER([S1], (NOT ISEMPTY([MEASURES].[STORE SALES]))))' " +
"SET [S1] " +
"AS 'CROSSJOIN({[GENDER].[GENDER].MEMBERS},{[STORE].[CANADA].CHILDREN})' " +
"SELECT\n" +
"{[MEASURES].[STORE SALES]} ON COLUMNS,\n" +
"{[GENDER].[AGG]} ON ROWS\n" +
"FROM [WAREHOUSE AND SALES]",
fold(
"Axis #0:\n" +
"{}\n" +
"Axis #1:\n" +
"{[Measures].[Store Sales]}\n" +
"Axis #2:\n" +
"{[Gender].[AGG]}\n" +
"Row #0: \n"));
} finally {
props.IgnoreMeasureForNonJoiningDimension.
set(ignoreMeasureForNonJoiningDimension);
}
}

/**
* A simple user-defined function which adds one to its argument, but
* sleeps 1 ms before doing so.
Expand Down

0 comments on commit 71d47d3

Please sign in to comment.