Search in sources :

Example 46 with Result

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

the class Checkin_7641 method testImplicitMember.

public void testImplicitMember() throws Exception {
    // explicit use of [Product].[Class1]
    String mdx = " select NON EMPTY Crossjoin(" + " Hierarchize(Union({[Product].[Class1]}, " + "[Product].[Class1].Children)), " + " {[Measures].[Requested Value], " + " [Measures].[Shipped Value]}" + ") ON COLUMNS," + " NON EMPTY Hierarchize(Union({[Geography].[All Regions]}," + "[Geography].[All Regions].Children)) ON ROWS" + " from [ImplicitMember]";
    Result result1 = getTestContext().executeQuery(mdx);
    String resultString1 = TestContext.toString(result1);
    Result result2 = getTestContext().executeQuery(mdx);
    String resultString2 = TestContext.toString(result2);
    assertEquals(resultString1, resultString2);
}
Also used : Result(mondrian.olap.Result)

Example 47 with Result

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

the class MultipleColsInTupleAggTest method testTotal.

public void testTotal() throws Exception {
    if (!isApplicable()) {
        return;
    }
    MondrianProperties props = MondrianProperties.instance();
    // get value without aggregates
    propSaver.set(props.UseAggregates, false);
    propSaver.set(props.ReadAggregates, false);
    String mdx = "select {[Measures].[Total]} on columns from [Fact]";
    Result result = getTestContext().executeQuery(mdx);
    Object v = result.getCell(new int[] { 0 }).getValue();
    String mdx2 = "select {[Measures].[Total]} on columns from [Fact] where " + "{[Product].[Cat One].[Prod Cat One].[One]}";
    Result aresult = getTestContext().executeQuery(mdx2);
    Object av = aresult.getCell(new int[] { 0 }).getValue();
    // unless there is a way to flush the cache,
    // I'm skeptical about these results
    propSaver.set(props.UseAggregates, true);
    propSaver.set(props.ReadAggregates, false);
    Result result1 = getTestContext().executeQuery(mdx);
    Object v1 = result1.getCell(new int[] { 0 }).getValue();
    assertTrue(v.equals(v1));
    Result aresult2 = getTestContext().executeQuery(mdx2);
    Object av1 = aresult2.getCell(new int[] { 0 }).getValue();
    assertTrue(av.equals(av1));
}
Also used : MondrianProperties(mondrian.olap.MondrianProperties) Result(mondrian.olap.Result)

Example 48 with Result

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

the class TestContext method assertQueryReturns.

/**
 * Executes a query and checks that the result is a given string, displaying a message if result does not match
 * desiredResult.
 */
public void assertQueryReturns(String message, String query, String desiredResult) {
    Result result = executeQuery(query);
    String resultString = toString(result);
    if (desiredResult != null) {
        assertEqualsVerbose(desiredResult, upgradeActual(resultString), true, message);
    }
}
Also used : Result(mondrian.olap.Result)

Example 49 with Result

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

the class TestContext method databaseIsValid.

/**
 * Tests whether the database is valid. Allows tests that depend on optional databases to figure out whether to
 * proceed.
 *
 * @return whether a database is present and correct
 */
public boolean databaseIsValid() {
    try {
        Connection connection = getConnection();
        String cubeName = getDefaultCubeName();
        if (cubeName.indexOf(' ') >= 0) {
            cubeName = Util.quoteMdxIdentifier(cubeName);
        }
        Query query = connection.parseQuery("select from " + cubeName);
        Result result = connection.execute(query);
        Util.discard(result);
        connection.close();
        return true;
    } catch (RuntimeException e) {
        Util.discard(e);
        return false;
    }
}
Also used : Query(mondrian.olap.Query) OlapConnection(org.olap4j.OlapConnection) Connection(mondrian.olap.Connection) Result(mondrian.olap.Result)

Example 50 with Result

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

the class TestContext method executeSingletonAxis.

/**
 * Executes a set expression which is expected to return 0 or 1 members. It is an error if the expression returns
 * tuples (as opposed to members), or if it returns two or more members.
 *
 * @param expression Expression string
 * @return Null if axis returns the empty set, member if axis returns one member. Throws otherwise.
 */
public Member executeSingletonAxis(String expression) {
    final String cubeName = getDefaultCubeName();
    Result result = executeQuery("select {" + expression + "} on columns from " + cubeName);
    Axis axis = result.getAxes()[0];
    switch(axis.getPositions().size()) {
        case 0:
            // yielded just the null member, the array will be empty.
            return null;
        case 1:
            // Java nulls should never happen during expression evaluation.
            Position position = axis.getPositions().get(0);
            Util.assertTrue(position.size() == 1);
            Member member = position.get(0);
            Util.assertTrue(member != null);
            return member;
        default:
            throw Util.newInternal("expression " + expression + " yielded " + axis.getPositions().size() + " positions");
    }
}
Also used : Position(mondrian.olap.Position) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis) CellSetAxis(org.olap4j.CellSetAxis) 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