use of mondrian.olap.Connection in project mondrian by pentaho.
the class BatchTestCase method getMeasure.
protected RolapStar.Measure getMeasure(String cube, String measureName) {
final Connection connection = getFoodMartConnection();
final boolean fail = true;
Cube salesCube = connection.getSchema().lookupCube(cube, fail);
Member measure = salesCube.getSchemaReader(null).getMemberByUniqueName(Util.parseIdentifier(measureName), fail);
return RolapStar.getStarMeasure(measure);
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method testUnparse.
public void testUnparse() {
Connection connection = getConnection();
Query query = connection.parseQuery("with member [Measures].[Rendite] as \n" + " '(([Measures].[Store Sales] - [Measures].[Store Cost])) / [Measures].[Store Cost]',\n" + " format_string = iif(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost] * 100 > \n" + " Parameter (\"UpperLimit\", NUMERIC, 151, \"Obere Grenze\"), \n" + " \"|#.00%|arrow='up'\",\n" + " iif(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost] * 100 < \n" + " Parameter(\"LowerLimit\", NUMERIC, 150, \"Untere Grenze\"),\n" + " \"|#.00%|arrow='down'\",\n" + " \"|#.00%|arrow='right'\"))\n" + "select {[Measures].members} on columns\n" + "from Sales");
final String s = Util.unparse(query);
// Parentheses are added to reflect operator precedence, but that's ok.
// Note that the doubled parentheses in line #2 of the query have been
// reduced to a single level.
TestContext.assertEqualsVerbose("with member [Measures].[Rendite] as '(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost])', " + "format_string = IIf((((([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost]) * 100) > Parameter(\"UpperLimit\", NUMERIC, 151, \"Obere Grenze\")), " + "\"|#.00%|arrow='up'\", " + "IIf((((([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost]) * 100) < Parameter(\"LowerLimit\", NUMERIC, 150, \"Untere Grenze\")), " + "\"|#.00%|arrow='down'\", \"|#.00%|arrow='right'\"))\n" + "select {[Measures].Members} ON COLUMNS\n" + "from [Sales]\n", s);
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method runMondrian1506.
private void runMondrian1506(Mondrian1506Lambda lambda) throws Exception {
if (getTestContext().getDialect().getDatabaseProduct() != Dialect.DatabaseProduct.MYSQL) {
// This only works on MySQL because of Sleep()
return;
}
final TestContext context = getTestContext().withSchema("<Schema name=\"Foo\">\n" + " <Cube name=\"Bar\">\n" + " <Table name=\"warehouse\">\n" + " <SQL>sleep(0.1) = 0</SQL>\n" + " </Table> \n" + " <Dimension name=\"Dim\">\n" + " <Hierarchy hasAll=\"true\">\n" + " <Level name=\"Level\" column=\"warehouse_id\"/>\n" + " </Hierarchy>\n" + " </Dimension>\n" + " <Measure name=\"Measure\" aggregator=\"sum\">\n" + " <MeasureExpression>\n" + " <SQL>1</SQL>\n" + " </MeasureExpression>\n" + " </Measure>\n" + " </Cube>\n" + "</Schema>\n");
final String mdx = "select {[Measures].[Measure]} on columns from [Bar]";
// A service to execute stuff in the background.
final ExecutorService exec = Util.getExecutorService(2, 2, 1000, "BasicQueryTest.testMondrian1506", new RejectedExecutionHandler() {
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
throw new RuntimeException();
}
});
// We are testing the old Query API.
final Connection connection = context.getConnection();
final Query q1 = connection.parseQuery(mdx);
final Query q2 = connection.parseQuery(mdx);
// Some flags to test.
final AtomicBoolean fail = new AtomicBoolean(false);
final AtomicBoolean success = new AtomicBoolean(false);
final Runnable r1 = new Runnable() {
public void run() {
try {
connection.execute(q1);
} catch (Throwable t) {
fail.set(true);
}
}
};
final Runnable r2 = new Runnable() {
public void run() {
try {
connection.execute(q2);
success.set(true);
} catch (Throwable t) {
t.printStackTrace();
}
}
};
try {
lambda.run(exec, q1, fail, success, r1, r2);
} finally {
exec.shutdownNow();
}
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method testMembersOfLargeDimensionTheHardWay.
public void testMembersOfLargeDimensionTheHardWay() {
// Avoid this test if memory is scarce.
if (Bug.avoidMemoryOverflow(TestContext.instance().getDialect())) {
return;
}
final Connection connection = TestContext.instance().getConnection();
String queryString = "select {[Measures].[Unit Sales]} on columns,\n" + "{[Customers].members} on rows\n" + "from Sales";
Query query = connection.parseQuery(queryString);
Result result = connection.execute(query);
assertEquals(10407, result.getAxes()[1].getPositions().size());
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method testUnparse2.
public void testUnparse2() {
Connection connection = getConnection();
Query query = connection.parseQuery("with member [Measures].[Foo] as '1', " + "format_string='##0.00', " + "funny=IIf(1=1,\"x\"\"y\",\"foo\") " + "select {[Measures].[Foo]} on columns from Sales");
final String s = query.toString();
// The "format_string" property, a string literal, is now delimited by
// double-quotes. This won't work in MSOLAP, but for Mondrian it's
// consistent with the fact that property values are expressions,
// not enclosed in single-quotes.
TestContext.assertEqualsVerbose("with member [Measures].[Foo] as '1', " + "format_string = \"##0.00\", " + "funny = IIf((1 = 1), \"x\"\"y\", \"foo\")\n" + "select {[Measures].[Foo]} ON COLUMNS\n" + "from [Sales]\n", s);
}
Aggregations