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);
}
}
}
}
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");
}
}
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);
}
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);
}
}
}
}
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");
}
Aggregations