Search in sources :

Example 36 with Result

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());
}
Also used : Result(mondrian.olap.Result)

Example 37 with Result

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());
}
Also used : Query(mondrian.olap.Query) OlapConnection(org.olap4j.OlapConnection) Connection(mondrian.olap.Connection) Cell(mondrian.olap.Cell) Result(mondrian.olap.Result)

Example 38 with Result

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);
}
Also used : Cell(mondrian.olap.Cell) Result(mondrian.olap.Result)

Example 39 with Result

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());
}
Also used : Cell(mondrian.olap.Cell) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result)

Example 40 with Result

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));
}
Also used : Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) TupleConstraint(mondrian.rolap.sql.TupleConstraint) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) Level(mondrian.olap.Level) Member(mondrian.olap.Member)

Aggregations

Result (mondrian.olap.Result)113 Axis (mondrian.olap.Axis)24 Member (mondrian.olap.Member)10 Test (org.junit.Test)10 Cell (mondrian.olap.Cell)9 Connection (mondrian.olap.Connection)9 Query (mondrian.olap.Query)9 Position (mondrian.olap.Position)8 TestContext (mondrian.test.TestContext)7 ArrayList (java.util.ArrayList)5 MondrianProperties (mondrian.olap.MondrianProperties)5 OlapElement (mondrian.olap.OlapElement)5 RolapCell (mondrian.rolap.RolapCell)5 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)5 Execution (mondrian.server.Execution)5 Dialect (mondrian.spi.Dialect)5 OlapConnection (org.olap4j.OlapConnection)5 List (java.util.List)4 ResultBase (mondrian.olap.ResultBase)4 Evaluator (mondrian.olap.Evaluator)3