Search in sources :

Example 86 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class TestContext method executeExprRaw.

/**
 * Executes the expression in the context of the cube indicated by
 * <code>cubeName</code>, and returns the result as a Cell.
 *
 * @param expression The expression to evaluate
 * @return Cell which is the result of the expression
 */
public Cell executeExprRaw(String expression) {
    final String queryString = generateExpression(expression);
    Result result = executeQuery(queryString);
    return result.getCell(new int[] { 0 });
}
Also used : Result(mondrian.olap.Result)

Example 87 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class NativeSetEvaluationTest method testDimensionUsageExecutedNatively.

public void testDimensionUsageExecutedNatively() {
    TestContext testContext = getTestContext();
    String mdx = "" + "with member Measures.q1Sales as '([Time].[1997].[Q1], Measures.[Unit Sales])'\n" + "select NonEmptyCrossjoin( [Time].[1997].[Q1], Gender.Gender.members) on 0 \n" + "from Sales where Measures.q1Sales";
    Result result = testContext.executeQuery(mdx);
    checkNative(mdx, result);
}
Also used : Result(mondrian.olap.Result)

Example 88 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class NonEmptyTest method testNonEmptyDescendants.

/**
 * Ensures that NON EMPTY Descendants is optimized. Ensures that Descendants as a side effect collects MemberChildren
 * that may be looked up in the cache.
 */
public void testNonEmptyDescendants() {
    // 'level.getMembers()' which create false negatives in this test.
    if (MondrianProperties.instance().TestExpDependencies.get() > 0) {
        return;
    }
    Connection con = getTestContext().withSchemaPool(false).getConnection();
    SmartMemberReader smr = getSmartMemberReader(con, "Customers");
    MemberCacheHelper smrch = smr.cacheHelper;
    clearAndHardenCache(smrch);
    SmartMemberReader ssmr = getSmartMemberReader(con, "Customers");
    MemberCacheHelper ssmrch = ssmr.cacheHelper;
    clearAndHardenCache(ssmrch);
    TestCase c = new TestCase(con, 45, 21, "select \n" + "{[Measures].[Unit Sales]} ON columns, " + "NON EMPTY {[Customers].[All Customers], Descendants([Customers].[All Customers].[USA].[CA], [Customers]" + ".[Name])} on rows " + "from [Sales] " + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
    Result result = c.run();
    // [Customers].[All Customers].[USA].[CA].[Burlingame].[Peggy Justice]
    RolapMember peggy = (RolapMember) result.getAxes()[1].getPositions().get(1).get(0);
    RolapMember burlingame = peggy.getParentMember();
    peggy = ((RolapCubeMember) peggy).getRolapMember();
    burlingame = ((RolapCubeMember) burlingame).getRolapMember();
    // all children of burlingame are not in cache
    MemberChildrenConstraint mcc = scf.getMemberChildrenConstraint(null);
    assertNull(ssmrch.mapMemberToChildren.get(burlingame, mcc));
    // but non empty children is
    Evaluator evaluator = getEvaluator(result, new int[] { 0, 0 });
    evaluator.setNonEmpty(true);
    mcc = scf.getMemberChildrenConstraint(evaluator);
    List<RolapMember> list = ssmrch.mapMemberToChildren.get(burlingame, mcc);
    assertNotNull(list);
    assertTrue(list.contains(peggy));
    // now we run the same query again, this time everything must come out
    // of the cache
    RolapNativeRegistry reg = getRegistry(con);
    reg.setListener(new Listener() {

        public void foundEvaluator(NativeEvent e) {
        }

        public void foundInCache(TupleEvent e) {
        }

        public void executingSql(TupleEvent e) {
            fail("expected caching");
        }
    });
    try {
        c.run();
    } finally {
        reg.setListener(null);
    }
}
Also used : Listener(mondrian.rolap.RolapNative.Listener) Connection(mondrian.olap.Connection) Evaluator(mondrian.olap.Evaluator) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result) MemberChildrenConstraint(mondrian.rolap.sql.MemberChildrenConstraint) TupleEvent(mondrian.rolap.RolapNative.TupleEvent) NativeEvent(mondrian.rolap.RolapNative.NativeEvent)

Example 89 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class NonEmptyTest method testNonEmptyUnionQuery.

public void testNonEmptyUnionQuery() {
    Result result = executeQuery("select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,\n" + " NON EMPTY Hierarchize(\n" + "   Union(\n" + "     Crossjoin(\n" + "       Crossjoin([Gender].[All Gender].children,\n" + "                 [Marital Status].[All Marital Status].children),\n" + "       Crossjoin([Customers].[All Customers].children,\n" + "                 [Product].[All Products].children) ),\n" + "     Crossjoin({([Gender].[All Gender].[M], [Marital Status].[All Marital Status].[M])},\n" + "       Crossjoin(\n" + "         [Customers].[All Customers].[USA].children,\n" + "         [Product].[All Products].children) ) )) on rows\n" + "from Sales where ([Time].[1997])");
    final Axis rowsAxis = result.getAxes()[1];
    Assert.assertEquals(21, rowsAxis.getPositions().size());
}
Also used : Axis(mondrian.olap.Axis) NonEmptyResult(mondrian.rolap.RolapConnection.NonEmptyResult) Result(mondrian.olap.Result)

Example 90 with Result

use of mondrian.olap.Result in project mondrian by pentaho.

the class RolapResultTest method _testNullDefaultMeasure.

/**
 * This ought to give the same result as the above testD2() method.
 * In this case, the FT2Extra cube has a default measure with no
 * data (null) for all members. This default measure is used
 * in the evaluation even though there is an implicit use of the
 * measure [Measures].[Value].
 *
 * @throws Exception
 */
public void _testNullDefaultMeasure() throws Exception {
    if (!isApplicable()) {
        return;
    }
    String mdx = "select " + " NON EMPTY filter({[D1].[a],[D1].[b],[D1].[c]}, " + "    [Measures].[Value] > 0) " + " ON COLUMNS, " + " {[D2].[x],[D2].[y],[D2].[z]} " + " ON ROWS " + "from FT2Extra";
    // getCubeTestContext().assertQueryReturns(mdx, RESULTS);
    Result result = getTestContext().executeQuery(mdx);
    String resultString = TestContext.toString(result);
    assertTrue(resultString.equals(RESULTS));
}
Also used : Result(mondrian.olap.Result)

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