Search in sources :

Example 11 with Cell

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

the class BasicQueryTest method testGetContext.

/**
 * Unit test for the {@link Cell#getContextMember(mondrian.olap.Hierarchy)}
 * method.
 */
public void testGetContext() {
    if (!MondrianProperties.instance().SsasCompatibleNaming.get()) {
        return;
    }
    Result result = getTestContext().executeQuery("select [Gender].Members on 0,\n" + "[Time].[Weekly].[1997].[6].Children on 1\n" + "from [Sales]\n" + "where [Marital Status].[S]");
    final Cell cell = result.getCell(new int[] { 0, 0 });
    final Map<String, Hierarchy> hierarchyMap = new HashMap<String, Hierarchy>();
    for (Dimension dimension : result.getQuery().getCube().getDimensions()) {
        for (Hierarchy hierarchy : dimension.getHierarchies()) {
            hierarchyMap.put(hierarchy.getUniqueName(), hierarchy);
        }
    }
    assertEquals("[Measures].[Unit Sales]", cell.getContextMember(hierarchyMap.get("[Measures]")).getUniqueName());
    assertEquals("[Time].[1997]", cell.getContextMember(hierarchyMap.get("[Time]")).getUniqueName());
    assertEquals("[Time].[Weekly].[1997].[6].[1]", cell.getContextMember(hierarchyMap.get("[Time].[Weekly]")).getUniqueName());
    assertEquals("[Gender].[All Gender]", cell.getContextMember(hierarchyMap.get("[Gender]")).getUniqueName());
    assertEquals("[Marital Status].[S]", cell.getContextMember(hierarchyMap.get("[Marital Status]")).getUniqueName());
}
Also used : Cell(mondrian.olap.Cell)

Example 12 with Cell

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

the class TestContext method assertExprReturns.

/**
 * Executes an expression and asserts that it returns a given result.
 */
public void assertExprReturns(String expression, String expected) {
    final Cell cell = executeExprRaw(expression);
    if (expected == null) {
        // null values are formatted as empty string
        expected = "";
    }
    assertEqualsVerbose(expected, cell.getFormattedValue());
}
Also used : Cell(mondrian.olap.Cell)

Example 13 with Cell

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

the class TestContext method cellIter.

/**
 * Returns an iterator over cells in a result.
 */
static Iterable<Cell> cellIter(final Result result) {
    return new Iterable<Cell>() {

        public Iterator<Cell> iterator() {
            int[] axisDimensions = new int[result.getAxes().length];
            int k = 0;
            for (Axis axis : result.getAxes()) {
                axisDimensions[k++] = axis.getPositions().size();
            }
            final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions);
            return new Iterator<Cell>() {

                public boolean hasNext() {
                    return coordIter.hasNext();
                }

                public Cell next() {
                    final int[] ints = coordIter.next();
                    return result.getCell(ints);
                }

                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}
Also used : CoordinateIterator(org.olap4j.impl.CoordinateIterator) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Cell(mondrian.olap.Cell) Axis(mondrian.olap.Axis)

Example 14 with Cell

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

the class UdfTest method testScriptUdfInvalid.

/**
 * Unit test that we get a nice error if a script UDF contains an error.
 */
public void testScriptUdfInvalid() {
    TestContext tc = udfTestContext("<UserDefinedFunction name='Factorial'>\n" + "  <Script language='JavaScript'><![CDATA[\n" + "    function getParameterTypes() {\n" + "      return new Array(\n" + "        new mondrian.olap.type.NumericType());\n" + "    }\n" + "    function getReturnType(parameterTypes) {\n" + "      return new mondrian.olap.type.NumericType();\n" + "    }\n" + "    function execute(evaluator, arguments) {\n" + "      var n = arguments[0].evaluateScalar(evaluator);\n" + "      return factorial(n);\n" + "    }\n" + "    function factorial(n) {\n" + "      return n <= 1 ? 1 : n * factorial_xx(n - 1);\n" + "    }\n" + "  ]]>\n" + "  </Script>\n" + "</UserDefinedFunction>\n");
    final Cell cell = tc.executeExprRaw("Factorial(4 + 2)");
    getTestContext().assertMatchesVerbose(Pattern.compile("(?s).*ReferenceError: \"factorial_xx\" is not defined..*"), cell.getValue().toString());
}
Also used : Cell(mondrian.olap.Cell)

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