Search in sources :

Example 6 with Axis

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

the class BasicQueryTest method testHierDifferentKeyClass.

/**
 * description of this testcase:
 * A calculated member is created on the time.month level.
 * On Hierarchize this member is compared to a month.
 * The month has a numeric key, while the calculated members
 * key type is string.
 * No exeception must be thrown.
 */
public void testHierDifferentKeyClass() {
    Result result = executeQuery("with member [Time].[Time].[1997].[Q1].[xxx] as\n" + "'Aggregate({[Time].[1997].[Q1].[1], [Time].[1997].[Q1].[2]})'\n" + "select {[Measures].[Unit Sales], [Measures].[Store Cost],\n" + "[Measures].[Store Sales]} ON columns,\n" + "Hierarchize(Union(Union({[Time].[1997], [Time].[1998],\n" + "[Time].[1997].[Q1].[xxx]}, [Time].[1997].Children),\n" + "[Time].[1997].[Q1].Children)) ON rows from [Sales]");
    Axis a = result.getAxes()[1];
    assertEquals(10, a.getPositions().size());
}
Also used : Axis(mondrian.olap.Axis)

Example 7 with Axis

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

the class TestContext method assertResultValid.

/**
 * Checks that a {@link Result} is valid.
 *
 * @param result Query result
 */
private void assertResultValid(Result result) {
    for (Cell cell : cellIter(result)) {
        final Object value = cell.getValue();
        // Check that the dummy value used to represent null cells never
        // leaks into the outside world.
        Assert.assertNotSame(value, Util.nullValue);
        Assert.assertFalse(value instanceof Number && ((Number) value).doubleValue() == FunUtil.DoubleNull);
        // Similarly empty values.
        Assert.assertNotSame(value, Util.EmptyValue);
        Assert.assertFalse(value instanceof Number && ((Number) value).doubleValue() == FunUtil.DoubleEmpty);
        // Cells should be null if and only if they are null or empty.
        if (cell.getValue() == null) {
            Assert.assertTrue(cell.isNull());
        } else {
            Assert.assertFalse(cell.isNull());
        }
    }
    // There should be no null members.
    for (Axis axis : result.getAxes()) {
        for (Position position : axis.getPositions()) {
            for (Member member : position) {
                Assert.assertNotNull(member);
            }
        }
    }
}
Also used : Position(mondrian.olap.Position) Cell(mondrian.olap.Cell) Axis(mondrian.olap.Axis)

Example 8 with Axis

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

Example 9 with Axis

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

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

the class ModulosTest method testThree.

public void testThree() {
    Axis[] axes = new Axis[3];
    TupleList positions = newPositionList(4);
    axes[0] = new RolapAxis(positions);
    positions = newPositionList(3);
    axes[1] = new RolapAxis(positions);
    positions = newPositionList(2);
    axes[2] = new RolapAxis(positions);
    Modulos modulosMany = Modulos.Generator.createMany(axes);
    Modulos modulos = Modulos.Generator.create(axes);
    int ordinal = 23;
    int[] posMany = modulosMany.getCellPos(ordinal);
    int[] pos = modulos.getCellPos(ordinal);
    assertTrue("Pos are not equal", Arrays.equals(posMany, pos));
    ordinal = 11;
    posMany = modulosMany.getCellPos(ordinal);
    pos = modulos.getCellPos(ordinal);
    assertTrue("Pos are not equal", Arrays.equals(posMany, pos));
    ordinal = 7;
    posMany = modulosMany.getCellPos(ordinal);
    pos = modulos.getCellPos(ordinal);
    assertTrue("Pos are not equal", Arrays.equals(posMany, pos));
    pos[0] = 3;
    pos[1] = 2;
    pos[2] = 1;
    int oMany = modulosMany.getCellOrdinal(pos);
    int o = modulos.getCellOrdinal(pos);
    assertTrue("Ordinals are not equal", oMany == o);
    pos[0] = 2;
    oMany = modulosMany.getCellOrdinal(pos);
    o = modulos.getCellOrdinal(pos);
    assertTrue("Ordinals are not equal", oMany == o);
    pos[0] = 1;
    oMany = modulosMany.getCellOrdinal(pos);
    o = modulos.getCellOrdinal(pos);
    assertTrue("Ordinals are not equal", oMany == o);
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) Axis(mondrian.olap.Axis)

Aggregations

Axis (mondrian.olap.Axis)38 Result (mondrian.olap.Result)9 Position (mondrian.olap.Position)8 List (java.util.List)7 Member (mondrian.olap.Member)7 Test (org.junit.Test)7 Cell (mondrian.olap.Cell)6 ArrayList (java.util.ArrayList)5 TupleList (mondrian.calc.TupleList)4 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)4 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 Hierarchy (mondrian.olap.Hierarchy)2 RolapAxis (mondrian.rolap.RolapAxis)2 DBCacheEntry (org.pentaho.di.core.DBCacheEntry)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2 RowMeta (org.pentaho.di.core.row.RowMeta)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)2 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)2