Search in sources :

Example 6 with Cell

use of mondrian.olap.Cell 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 : Connection(mondrian.olap.Connection) Cell(mondrian.olap.Cell)

Example 7 with Cell

use of mondrian.olap.Cell 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)

Example 8 with Cell

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

the class UdfTest method testException.

public void testException() {
    Result result = executeQuery("WITH MEMBER [Measures].[InverseNormal] " + " AS 'InverseNormal([Measures].[Store Sqft] / [Measures].[Grocery Sqft])'," + " FORMAT_STRING = \"0.000000\"\n" + "SELECT {[Measures].[InverseNormal]} ON COLUMNS, \n" + "  {[Store Type].children} ON ROWS \n" + "FROM [Store]");
    Axis rowAxis = result.getAxes()[0];
    assertTrue(rowAxis.getPositions().size() == 1);
    Axis colAxis = result.getAxes()[1];
    assertTrue(colAxis.getPositions().size() == 6);
    Cell cell = result.getCell(new int[] { 0, 0 });
    assertTrue(cell.isError());
    getTestContext().assertMatchesVerbose(Pattern.compile("(?s).*Invalid value for inverse normal distribution: 1.4708.*"), cell.getValue().toString());
    cell = result.getCell(new int[] { 0, 5 });
    assertTrue(cell.isError());
    getTestContext().assertMatchesVerbose(Pattern.compile("(?s).*Invalid value for inverse normal distribution: 1.4435.*"), cell.getValue().toString());
}
Also used : Cell(mondrian.olap.Cell) Axis(mondrian.olap.Axis)

Example 9 with Cell

use of mondrian.olap.Cell 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 10 with Cell

use of mondrian.olap.Cell in project pentaho-kettle by pentaho.

the class MondrianHelper method outputFlattenedRecurse.

private static void outputFlattenedRecurse(Result result, List<List<Object>> rows, List<Object> rowValues, int[] coords, int axisOrdinal) {
    final Axis[] axes = result.getAxes();
    if (axisOrdinal == axes.length) {
        final Cell cell = result.getCell(coords);
        // Output the raw (unformatted) value of the cell.
        // NOTE: We could output other properties of the cell here, such as its
        // formatted value, too.
        rowValues.add(cell.getValue());
        // Add a copy of the completed row to the list of rows.
        rows.add(new ArrayList<>(rowValues));
    } else {
        final Axis axis = axes[axisOrdinal];
        int k = -1;
        int saveLength = rowValues.size();
        for (Position position : axis.getPositions()) {
            coords[axisOrdinal] = ++k;
            for (Member member : position) {
                rowValues.add(member.getUniqueName());
            }
            outputFlattenedRecurse(result, rows, rowValues, coords, axisOrdinal + 1);
            while (rowValues.size() > saveLength) {
                rowValues.remove(rowValues.size() - 1);
            }
        }
    }
}
Also used : Position(mondrian.olap.Position) Cell(mondrian.olap.Cell) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis)

Aggregations

Cell (mondrian.olap.Cell)14 Axis (mondrian.olap.Axis)6 Position (mondrian.olap.Position)3 Member (mondrian.olap.Member)2 CoordinateIterator (org.olap4j.impl.CoordinateIterator)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Connection (mondrian.olap.Connection)1 Result (mondrian.olap.Result)1 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)1 org.olap4j (org.olap4j)1 DBCacheEntry (org.pentaho.di.core.DBCacheEntry)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)1 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)1 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)1