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