use of mondrian.olap.Connection in project mondrian by pentaho.
the class RolapStarTest method getStar.
RolapStarForTests getStar(String starName) {
Connection con = getTestContext().getConnection();
RolapStar rs = getStar(con, starName);
return new RolapStarForTests(rs.getSchema(), rs.getDataSource(), rs.getFactTable().getRelation());
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class SqlConstraintUtilsTest method testExpandSupportedCalculatedMembers2.
// test with a placeholder member
public void testExpandSupportedCalculatedMembers2() {
final TestContext testContext = TestContext.instance();
final Connection connection = testContext.getConnection();
final String queryText = "SELECT {[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE [Time].[1997]";
final Query query = connection.parseQuery(queryText);
final QueryAxis querySlicerAxis = query.getSlicerAxis();
final Member slicerMember = ((MemberExpr) querySlicerAxis.getSet()).getMember();
final RolapHierarchy slicerHierarchy = ((RolapCube) query.getCube()).getTimeHierarchy(null);
final Execution execution = new Execution(query.getStatement(), 0L);
final RolapEvaluatorRoot rolapEvaluatorRoot = new RolapEvaluatorRoot(execution);
final RolapEvaluator rolapEvaluator = new RolapEvaluator(rolapEvaluatorRoot);
final Member expectedMember = slicerMember;
rolapEvaluator.setSlicerContext(expectedMember);
RolapResult.CompoundSlicerRolapMember placeHolderMember = Mockito.mock(RolapResult.CompoundSlicerRolapMember.class);
Mockito.doReturn(slicerHierarchy).when(placeHolderMember).getHierarchy();
Member endMember0 = makeNoncalculatedMember("0");
// (0, placeholder)
Member[] argMembers = new Member[] { endMember0, placeHolderMember };
Member[] expectedMembers = new Member[] { endMember0, slicerMember };
Member[] expectedMembersOnDisjoin = new Member[] { endMember0 };
assertApartExpandSupportedCalculatedMembers("(0, placeholder)", expectedMembers, expectedMembersOnDisjoin, argMembers, rolapEvaluator);
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method executeAndCancel.
private void executeAndCancel(String queryString, int waitMillis) {
final TestContext tc = TestContext.instance().create(null, null, null, null, "<UserDefinedFunction name=\"SleepUdf\" className=\"" + SleepUdf.class.getName() + "\"/>", null);
Connection connection = tc.getConnection();
final Query query = connection.parseQuery(queryString);
final Throwable[] throwables = { null };
if (waitMillis == 0) {
// cancel immediately
try {
query.getStatement().cancel();
} catch (Exception e) {
throwables[0] = e;
}
} else {
// Schedule timer to cancel after waitMillis
Timer timer = new Timer(true);
TimerTask task = new TimerTask() {
public void run() {
Thread thread = Thread.currentThread();
thread.setName("CancelThread");
try {
query.getStatement().cancel();
} catch (Exception e) {
throwables[0] = e;
}
}
};
timer.schedule(task, waitMillis);
}
if (throwables[0] != null) {
Assert.fail("Cancel request failed: " + throwables[0]);
}
Throwable throwable = null;
try {
connection.execute(query);
} catch (Throwable ex) {
throwable = ex;
}
if (throwables[0] != null) {
Assert.fail("Cancel request failed: " + throwables[0]);
}
TestContext.checkThrowable(throwable, "canceled");
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method _testBug793616.
/**
* Bug 793616: Deeply nested UNION function takes forever to validate.
* (Problem was that each argument of a function was validated twice, hence
* the validation time was <code>O(2 ^ depth)</code>.)
*/
public void _testBug793616() {
if (props.TestExpDependencies.get() > 0) {
// returned.
return;
}
final long start = System.currentTimeMillis();
Connection connection = getTestContext().getConnection();
final String queryString = "select {[Measures].[Unit Sales],\n" + " [Measures].[Store Cost],\n" + " [Measures].[Store Sales]} ON columns,\n" + "Hierarchize(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union\n" + "({([Gender].[All Gender],\n" + " [Marital Status].[All Marital Status],\n" + " [Customers].[All Customers],\n" + " [Product].[All Products])},\n" + " Crossjoin ([Gender].[All Gender].Children,\n" + " {([Marital Status].[All Marital Status],\n" + " [Customers].[All Customers],\n" + " [Product].[All Products])})),\n" + " Crossjoin(Crossjoin({[Gender].[All Gender].[F]},\n" + " [Marital Status].[All Marital Status].Children),\n" + " {([Customers].[All Customers],\n" + " [Product].[All Products])})),\n" + " Crossjoin(Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[M])},\n" + " [Customers].[All Customers].Children),\n" + " {[Product].[All Products]})),\n" + " Crossjoin(Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[M])},\n" + " [Customers].[All Customers].[USA].Children),\n" + " {[Product].[All Products]})),\n" + " Crossjoin ({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA].[CA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA].[OR])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA].[WA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin ({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin(\n" + " Crossjoin({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[S])}, [Customers].[All Customers].Children),\n" + " {[Product].[All Products]})),\n" + " Crossjoin(Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[S])},\n" + " [Customers].[All Customers].[USA].Children),\n" + " {[Product].[All Products]})),\n" + " Crossjoin ({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[S],\n" + " [Customers].[All Customers].[USA].[CA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[S],\n" + " [Customers].[All Customers].[USA].[OR])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[S],\n" + " [Customers].[All Customers].[USA].[WA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin ({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status].[S],\n" + " [Customers].[All Customers].[USA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin(Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status])},\n" + " [Customers].[All Customers].Children),\n" + " {[Product].[All Products]})),\n" + " Crossjoin(Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status])},\n" + " [Customers].[All Customers].[USA].Children),\n" + " {[Product].[All Products]})),\n" + " Crossjoin ({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status],\n" + " [Customers].[All Customers].[USA].[CA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status],\n" + " [Customers].[All Customers].[USA].[OR])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status],\n" + " [Customers].[All Customers].[USA].[WA])},\n" + " [Product].[All Products].Children)),\n" + " Crossjoin ({([Gender].[All Gender].[F],\n" + " [Marital Status].[All Marital Status],\n" + " [Customers].[All Customers].[USA])},\n" + " [Product].[All Products].Children))) ON rows from [Sales] where [Time].[1997]";
Query query = connection.parseQuery(queryString);
// If this call took longer than 10 seconds, the performance bug has
// probably resurfaced again.
final long afterParseMillis = System.currentTimeMillis();
final long afterParseNonDbMillis = afterParseMillis - Util.dbTimeMillis();
final long parseMillis = afterParseMillis - start;
assertTrue("performance problem: parse took " + parseMillis + " milliseconds", parseMillis <= 10000);
Result result = connection.execute(query);
assertEquals(59, result.getAxes()[1].getPositions().size());
// If this call took longer than 10 seconds,
// or 2 seconds exclusing db access,
// the performance bug has
// probably resurfaced again.
final long afterExecMillis = System.currentTimeMillis();
final long afterExecNonDbMillis = afterExecMillis - Util.dbTimeMillis();
final long execNonDbMillis = afterExecNonDbMillis - afterParseNonDbMillis;
final long execMillis = (afterExecMillis - afterParseMillis);
assertTrue("performance problem: execute took " + execMillis + " milliseconds, " + execNonDbMillis + " milliseconds excluding db", execNonDbMillis <= 2000 && execMillis <= 30000);
}
use of mondrian.olap.Connection in project mondrian by pentaho.
the class BasicQueryTest method testQueryIterationLimit.
public void testQueryIterationLimit() {
// Query will need to iterate 4*3 times to compute aggregates,
// so set iteration limit to 11
String queryString = "With Set [*NATIVE_CJ_SET] as " + "'NonEmptyCrossJoin([*BASE_MEMBERS_Dates], [*BASE_MEMBERS_Stores])' " + "Set [*BASE_MEMBERS_Dates] as '{[Time].[1997].[Q1], [Time].[1997].[Q2], [Time].[1997].[Q3], [Time].[1997].[Q4]}' " + "Set [*GENERATED_MEMBERS_Dates] as 'Generate([*NATIVE_CJ_SET], {[Time].[Time].CurrentMember})' " + "Set [*GENERATED_MEMBERS_Measures] as '{[Measures].[*SUMMARY_METRIC_0]}' " + "Set [*BASE_MEMBERS_Stores] as '{[Store].[USA].[CA], [Store].[USA].[WA], [Store].[USA].[OR]}' " + "Set [*GENERATED_MEMBERS_Stores] as 'Generate([*NATIVE_CJ_SET], {[Store].CurrentMember})' " + "Member [Time].[Time].[*SM_CTX_SEL] as 'Aggregate([*GENERATED_MEMBERS_Dates])' " + "Member [Measures].[*SUMMARY_METRIC_0] as '[Measures].[Unit Sales]/([Measures].[Unit Sales],[Time].[*SM_CTX_SEL])' " + "Member [Time].[Time].[*SUBTOTAL_MEMBER_SEL~SUM] as 'sum([*GENERATED_MEMBERS_Dates])' " + "Member [Store].[*SUBTOTAL_MEMBER_SEL~SUM] as 'sum([*GENERATED_MEMBERS_Stores])' " + "select crossjoin({[Time].[*SUBTOTAL_MEMBER_SEL~SUM]}, {[Store].[*SUBTOTAL_MEMBER_SEL~SUM]}) " + "on columns from [Sales]";
propSaver.set(props.IterationLimit, 11);
Throwable throwable = null;
try {
Connection connection = getConnection();
Query query = connection.parseQuery(queryString);
query.setResultStyle(ResultStyle.LIST);
connection.execute(query);
} catch (Throwable ex) {
throwable = ex;
}
TestContext.checkThrowable(throwable, "Number of iterations exceeded limit of 11");
// make sure the query runs without the limit set
propSaver.reset();
executeQuery(queryString);
}
Aggregations