use of mondrian.olap.Result in project mondrian by pentaho.
the class PerformanceTest method testBugMondrian1242.
/**
* Test for
* <a href="http://jira.pentaho.com/browse/MONDRIAN-1242">MONDRIAN-1242,
* "Slicer size is exponentially inflating the cell requests"</a>. This case just checks correctness; a similar case
* in {@link PerformanceTest} checks performance.
*/
public void testBugMondrian1242() {
final TestContext testContext = getTestContext().create(null, null, null, null, "<UserDefinedFunction name=\"StringMult\" className=\"" + CounterUdf.class.getName() + "\"/>\n", null);
// original test case for MONDRIAN-1242; ensures correct result
testContext.assertQueryReturns("select {[Measures].[Unit Sales]} on COLUMNS,\n" + "[Store].[USA].[CA].Children on ROWS\n" + "from [Sales]\n" + "where ([Time.Weekly].[All Time.Weeklys].[1997].[4].[16]\n" + " : [Time.Weekly].[All Time.Weeklys].[1997].[5].[25])", "Axis #0:\n" + "{[Time].[Weekly].[1997].[4].[16]}\n" + "{[Time].[Weekly].[1997].[4].[17]}\n" + "{[Time].[Weekly].[1997].[4].[18]}\n" + "{[Time].[Weekly].[1997].[5].[19]}\n" + "{[Time].[Weekly].[1997].[5].[20]}\n" + "{[Time].[Weekly].[1997].[5].[21]}\n" + "{[Time].[Weekly].[1997].[5].[22]}\n" + "{[Time].[Weekly].[1997].[5].[23]}\n" + "{[Time].[Weekly].[1997].[5].[24]}\n" + "{[Time].[Weekly].[1997].[5].[25]}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Store].[USA].[CA].[Alameda]}\n" + "{[Store].[USA].[CA].[Beverly Hills]}\n" + "{[Store].[USA].[CA].[Los Angeles]}\n" + "{[Store].[USA].[CA].[San Diego]}\n" + "{[Store].[USA].[CA].[San Francisco]}\n" + "Row #0: \n" + "Row #1: 250\n" + "Row #2: 724\n" + "Row #3: 451\n" + "Row #4: 18\n");
CounterUdf.count.set(0);
Result result = testContext.executeQuery("with member [Measures].[Foo] as CounterUdf()\n" + "select {[Measures].[Foo]} on COLUMNS,\n" + "[Gender].Children on ROWS\n" + "from [Sales]\n" + "where ([Customers].[USA].[CA].[Altadena].[Alice Cantrell]" + " : [Customers].[USA].[CA].[Altadena].[Alice Cantrell].Lead(7000))");
assertEquals("111,191", result.getCell(new int[] { 0, 0 }).getFormattedValue());
// Count is 4 if bug is fixed,
// 28004 if bug is not fixed.
assertEquals(4, CounterUdf.count.get());
}
use of mondrian.olap.Result in project mondrian by pentaho.
the class TestContext method assertParameterizedExprReturns.
/**
* Asserts that an expression, with a given set of parameter bindings, returns a given result.
*
* @param expr Scalar MDX expression
* @param expected Expected result
* @param paramValues Array of parameter names and values
*/
public void assertParameterizedExprReturns(String expr, String expected, Object... paramValues) {
Connection connection = getConnection();
String queryString = generateExpression(expr);
Query query = connection.parseQuery(queryString);
assert paramValues.length % 2 == 0;
for (int i = 0; i < paramValues.length; ) {
final String paramName = (String) paramValues[i++];
final Object value = paramValues[i++];
query.setParameter(paramName, value);
}
final Result result = connection.execute(query);
final Cell cell = result.getCell(new int[] { 0 });
if (expected == null) {
// null values are formatted as empty string
expected = "";
}
assertEqualsVerbose(expected, cell.getFormattedValue());
}
use of mondrian.olap.Result in project mondrian by pentaho.
the class TestContext method assertExprThrows.
/**
* Executes an expression, and asserts that it gives an error which contains a particular pattern. The error might
* occur during parsing, or might be contained within the cell value.
*/
public void assertExprThrows(String expression, String pattern) {
Throwable throwable = null;
try {
String cubeName = getDefaultCubeName();
if (cubeName.indexOf(' ') >= 0) {
cubeName = Util.quoteMdxIdentifier(cubeName);
}
expression = Util.replace(expression, "'", "''");
Result result = executeQuery("with member [Measures].[Foo] as '" + expression + "' select {[Measures].[Foo]} on columns from " + cubeName);
Cell cell = result.getCell(new int[] { 0 });
if (cell.isError()) {
throwable = (Throwable) cell.getValue();
}
} catch (Throwable e) {
throwable = e;
}
checkThrowable(throwable, pattern);
}
use of mondrian.olap.Result in project mondrian by pentaho.
the class NonEmptyTest method testCalcMemberWithNonEmptyCrossJoin.
/**
* Make sure that the Crossjoin in [Measures].[CustomerCount] is not evaluated in NON EMPTY context.
*/
public void testCalcMemberWithNonEmptyCrossJoin() {
getConnection().getCacheControl(null).flushSchemaCache();
Result result = executeQuery("with member [Measures].[CustomerCount] as \n" + "'Count(CrossJoin({[Product].[All Products]}, [Customers].[Name].Members))'\n" + "select \n" + "NON EMPTY{[Measures].[CustomerCount]} ON columns,\n" + "NON EMPTY{[Product].[All Products]} ON rows\n" + "from [Sales]\n" + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
Cell c = result.getCell(new int[] { 0, 0 });
// we expect 10281 customers, although there are only 20 non-empty ones
// @see #testLevelMembers
assertEquals("10,281", c.getFormattedValue());
}
use of mondrian.olap.Result in project mondrian by pentaho.
the class NonEmptyTest method testLevelMembers.
public void testLevelMembers() {
if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
// test.
return;
}
SmartMemberReader smr = getSmartMemberReader("Customers");
// use the RolapCubeHierarchy's member cache for levels
MemberCacheHelper smrch = ((RolapCubeHierarchy.CacheRolapCubeHierarchyMemberReader) smr).rolapCubeCacheHelper;
clearAndHardenCache(smrch);
MemberCacheHelper smrich = smr.cacheHelper;
clearAndHardenCache(smrich);
// use the shared member cache for mapMemberToChildren
SmartMemberReader ssmr = getSharedSmartMemberReader("Customers");
MemberCacheHelper ssmrch = ssmr.cacheHelper;
clearAndHardenCache(ssmrch);
TestCase c = new TestCase(50, 21, "select \n" + "{[Measures].[Unit Sales]} ON columns,\n" + "NON EMPTY {[Customers].[All Customers], [Customers].[Name].Members} ON rows\n" + "from [Sales]\n" + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
Result r = c.run();
Level[] levels = smr.getHierarchy().getLevels();
Level nameLevel = levels[levels.length - 1];
// evaluator for [All Customers], [Store 14], [1/1/1997]
Evaluator context = getEvaluator(r, new int[] { 0, 0 });
// make sure that [Customers].[Name].Members is NOT in cache
TupleConstraint lmc = scf.getLevelMembersConstraint(null);
assertNull(smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc));
// make sure that NON EMPTY [Customers].[Name].Members IS in cache
context.setNonEmpty(true);
lmc = scf.getLevelMembersConstraint(context);
List<RolapMember> list = smrch.mapLevelToMembers.get((RolapLevel) nameLevel, lmc);
if (MondrianProperties.instance().EnableRolapCubeMemberCache.get()) {
assertNotNull(list);
assertEquals(20, list.size());
}
// make sure that the parent/child for the context are cached
// [Customers].[USA].[CA].[Burlingame].[Peggy Justice]
Member member = r.getAxes()[1].getPositions().get(1).get(0);
Member parent = member.getParentMember();
parent = ((RolapCubeMember) parent).getRolapMember();
member = ((RolapCubeMember) member).getRolapMember();
// lookup all children of [Burlingame] -> not in cache
MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
assertNull(ssmrch.mapMemberToChildren.get((RolapMember) parent, mcc));
// lookup NON EMPTY children of [Burlingame] -> yes these are in cache
mcc = scf.getMemberChildrenConstraint(context);
list = smrich.mapMemberToChildren.get((RolapMember) parent, mcc);
assertNotNull(list);
assertTrue(list.contains(member));
}
Aggregations