Search in sources :

Example 6 with Position

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

use of mondrian.olap.Position 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 8 with Position

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

the class RolapAxisTest method testMemberArrayList.

public void testMemberArrayList() {
    TupleList list = TupleCollections.createList(3);
    list.add(Arrays.<Member>asList(new TestMember("a"), new TestMember("b"), new TestMember("c")));
    list.add(Arrays.<Member>asList(new TestMember("d"), new TestMember("e"), new TestMember("f")));
    list.add(Arrays.<Member>asList(new TestMember("g"), new TestMember("h"), new TestMember("i")));
    StringBuilder buf = new StringBuilder(100);
    RolapAxis axis = new RolapAxis(list);
    List<Position> positions = axis.getPositions();
    boolean firstTimeInner = true;
    for (Position position : positions) {
        if (!firstTimeInner) {
            buf.append(',');
        }
        buf.append(toString(position));
        firstTimeInner = false;
    }
    String s = buf.toString();
    String e = "{a,b,c},{d,e,f},{g,h,i}";
    // System.out.println("s=" +s);
    Assert.assertEquals(s, e);
    positions = axis.getPositions();
    int size = positions.size();
    // System.out.println("size=" +size);
    Assert.assertEquals(size, 3);
    buf.setLength(0);
    for (int i = 0; i < size; i++) {
        Position position = positions.get(i);
        if (i > 0) {
            buf.append(',');
        }
        buf.append(toString(position));
    }
    s = buf.toString();
    e = "{a,b,c},{d,e,f},{g,h,i}";
    // System.out.println("s=" +s);
    Assert.assertEquals(s, e);
}
Also used : TupleList(mondrian.calc.TupleList) Position(mondrian.olap.Position) TestMember(mondrian.olap.fun.TestMember)

Example 9 with Position

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

Example 10 with Position

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

the class BasicQueryTest method testAllMemberCaption.

public void testAllMemberCaption() {
    TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name=\"Gender3\" foreignKey=\"customer_id\">\n" + "  <Hierarchy hasAll=\"true\" allMemberName=\"All Gender\"\n" + " allMemberCaption=\"Frauen und Maenner\" primaryKey=\"customer_id\">\n" + "  <Table name=\"customer\"/>\n" + "    <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>\n" + "  </Hierarchy>\n" + "</Dimension>");
    String mdx = "select {[Gender3].[All Gender]} on columns from Sales";
    Result result = testContext.executeQuery(mdx);
    Axis axis0 = result.getAxes()[0];
    Position pos0 = axis0.getPositions().get(0);
    Member allGender = pos0.get(0);
    String caption = allGender.getCaption();
    Assert.assertEquals(caption, "Frauen und Maenner");
}
Also used : Position(mondrian.olap.Position) Axis(mondrian.olap.Axis)

Aggregations

Position (mondrian.olap.Position)11 Axis (mondrian.olap.Axis)8 Member (mondrian.olap.Member)5 Cell (mondrian.olap.Cell)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)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 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TupleList (mondrian.calc.TupleList)1 Hierarchy (mondrian.olap.Hierarchy)1 Result (mondrian.olap.Result)1 TestMember (mondrian.olap.fun.TestMember)1