use of mondrian.olap.Cell in project mondrian by pentaho.
the class TestContext method assertParameterizedExprReturns.
/**
* Asserts that an expression, with a given set of parameter bindings,
* returns a given result.
*
* @param expr Scalar MDX expression
* @param expected Expected result
* @param paramValues Array of parameter names and values
*/
public void assertParameterizedExprReturns(String expr, String expected, Object... paramValues) {
Connection connection = getConnection();
String queryString = generateExpression(expr);
Query query = connection.parseQuery(queryString);
assert paramValues.length % 2 == 0;
for (int i = 0; i < paramValues.length; ) {
final String paramName = (String) paramValues[i++];
final Object value = paramValues[i++];
query.setParameter(paramName, value);
}
final Result result = connection.execute(query);
final Cell cell = result.getCell(new int[] { 0 });
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 assertExprThrows.
/**
* Executes an expression, and asserts that it gives an error which contains
* a particular pattern. The error might occur during parsing, or might
* be contained within the cell value.
*/
public void assertExprThrows(String expression, String pattern) {
Throwable throwable = null;
try {
String cubeName = getDefaultCubeName();
if (cubeName.indexOf(' ') >= 0) {
cubeName = Util.quoteMdxIdentifier(cubeName);
}
expression = Util.replace(expression, "'", "''");
Result result = executeQuery("with member [Measures].[Foo] as '" + expression + "' select {[Measures].[Foo]} on columns from " + cubeName);
Cell cell = result.getCell(new int[] { 0 });
if (cell.isError()) {
throwable = (Throwable) cell.getValue();
}
} catch (Throwable e) {
throwable = e;
}
checkThrowable(throwable, pattern);
}
use of mondrian.olap.Cell 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.Cell in project mondrian by pentaho.
the class NonEmptyTest method testCalcMemberWithNonEmptyCrossJoin.
/**
* Make sure that the Crossjoin in [Measures].[CustomerCount]
* is not evaluated in NON EMPTY context.
*/
public void testCalcMemberWithNonEmptyCrossJoin() {
getConnection().getCacheControl(null).flushSchemaCache();
Result result = executeQuery("with member [Measures].[CustomerCount] as \n" + "'Count(CrossJoin({[Product].[All Products]}, [Customers].[Name].Members))'\n" + "select \n" + "NON EMPTY{[Measures].[CustomerCount]} ON columns,\n" + "NON EMPTY{[Product].[All Products]} ON rows\n" + "from [Sales]\n" + "where ([Store].[All Stores].[USA].[CA].[San Francisco].[Store 14], [Time].[1997].[Q1].[1])");
Cell c = result.getCell(new int[] { 0, 0 });
// we expect 10281 customers, although there are only 20 non-empty ones
// @see #testLevelMembers
assertEquals("10,281", c.getFormattedValue());
}
use of mondrian.olap.Cell 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);
}
}
}
}
Aggregations