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