use of org.olap4j.metadata.Cube in project mondrian by pentaho.
the class Olap4jTest method foo.
private Member foo(int i) throws SQLException {
final OlapConnection connection = getTestContext().getOlap4jConnection();
final Cube cube;
final Hierarchy measuresHierarchy;
final CellSet cellSet;
switch(i) {
case 0:
cellSet = connection.createStatement().executeOlapQuery("select [Measures].[Unit Sales] on 0\n" + "from [Sales]");
return cellSet.getAxes().get(0).getPositions().get(0).getMembers().get(0);
case 1:
cellSet = connection.createStatement().executeOlapQuery("select [Measures].Members on 0\n" + "from [Sales]");
return cellSet.getAxes().get(0).getPositions().get(0).getMembers().get(0);
case 2:
cellSet = connection.createStatement().executeOlapQuery("select [Measures].[Measures].Members on 0\n" + "from [Sales]");
return cellSet.getAxes().get(0).getPositions().get(0).getMembers().get(0);
case 3:
cube = connection.getOlapSchema().getCubes().get("Sales");
measuresHierarchy = cube.getHierarchies().get("Measures");
final NamedList<Member> rootMembers = measuresHierarchy.getRootMembers();
return rootMembers.get(0);
case 4:
cube = connection.getOlapSchema().getCubes().get("Sales");
measuresHierarchy = cube.getHierarchies().get("Measures");
final Level measuresLevel = measuresHierarchy.getLevels().get(0);
final List<Member> levelMembers = measuresLevel.getMembers();
return levelMembers.get(0);
case 5:
cube = connection.getOlapSchema().getCubes().get("Sales");
measuresHierarchy = cube.getHierarchies().get("Measures");
return measuresHierarchy.getDefaultMember();
case 6:
cube = connection.getOlapSchema().getCubes().get("Sales");
return cube.lookupMember(IdentifierNode.parseIdentifier("[Measures].[Unit Sales]").getSegmentList());
default:
throw new IllegalArgumentException("bad index " + i);
}
}
use of org.olap4j.metadata.Cube in project mondrian by pentaho.
the class Olap4jTest method checkBugMondrian1217.
private void checkBugMondrian1217(final int cancelMin, final int cancelMax) throws SQLException {
assert cancelMin < cancelMax;
final AtomicBoolean finished = new AtomicBoolean(false);
final AtomicInteger failCount = new AtomicInteger();
final AtomicInteger cancelCount = new AtomicInteger();
final AtomicInteger tryCancelCount = new AtomicInteger();
final AtomicInteger actualCancelCount = new AtomicInteger();
final AtomicReference<Statement> stmtRef = new AtomicReference<Statement>();
try {
TestContext testContext = TestContext.instance();
final OlapConnection connection = testContext.getOlap4jConnection();
final Thread thread = new Thread(new Runnable() {
public void run() {
final Random random = new Random();
while (!finished.get()) {
try {
Thread.sleep(random.nextInt(cancelMax - cancelMin) + cancelMin);
} catch (InterruptedException e) {
return;
}
try {
Statement statement = stmtRef.get();
tryCancelCount.incrementAndGet();
if (statement != null) {
actualCancelCount.incrementAndGet();
statement.cancel();
}
} catch (SQLException e) {
failCount.incrementAndGet();
e.printStackTrace();
}
}
}
});
thread.start();
CacheControl cacheControl = testContext.getCacheControl();
Cube cube0 = connection.getOlapSchema().getCubes().get("Sales");
mondrian.olap.Cube cube = ((OlapWrapper) cube0).unwrap(mondrian.olap.Cube.class);
CacheControl.CellRegion cellRegion = cacheControl.createMeasuresRegion(cube);
final Random random = new Random();
final String[] queries = { "select [Product].Members on 0 from [Sales]", "select [Product].[Drink].Children on 0 from [Sales]", "select [Product].[Food].Children on 0 from [Sales]" };
for (int i = 0; ; i++) {
if (i % 10 == 0) {
cacheControl.flush(cellRegion);
}
final OlapStatement statement = connection.createStatement();
stmtRef.set(statement);
try {
final CellSet cellSet = statement.executeOlapQuery(queries[i == 0 ? 0 : random.nextInt(3)]);
String s = TestContext.toString(cellSet);
assertNotNull(s);
cellSet.close();
} catch (OlapException e) {
assertEquals(Arrays.toString(Util.convertStackToString(e)), "Query canceled", e.getMessage());
cancelCount.incrementAndGet();
}
statement.close();
stmtRef.set(null);
System.out.println("i=" + i + ", failCount=" + failCount + ", tryCancelCount=" + tryCancelCount + ", actualCancelCount=" + tryCancelCount + ", cancelCount=" + tryCancelCount);
}
} finally {
finished.set(true);
}
}
use of org.olap4j.metadata.Cube in project mondrian by pentaho.
the class Olap4jTest method testAnnotation.
public void testAnnotation() throws SQLException {
final OlapConnection connection = getTestContext().getOlap4jConnection();
final CellSet cellSet = connection.createStatement().executeOlapQuery("select from [Sales]");
final CellSetMetaData metaData = cellSet.getMetaData();
final Cube salesCube = metaData.getCube();
Annotated annotated = ((OlapWrapper) salesCube).unwrap(Annotated.class);
final Annotation annotation = annotated.getAnnotationMap().get("caption.fr_FR");
assertEquals("Ventes", annotation.getValue());
final Map<String, Object> map = XmlaHandler.getExtra(connection).getAnnotationMap(salesCube);
assertEquals("Ventes", map.get("caption.fr_FR"));
}
use of org.olap4j.metadata.Cube in project mondrian by pentaho.
the class Olap4jTest method testCalcMemberInCube.
/**
* Test case for bug <a href="http://jira.pentaho.com/browse/MONDRIAN-1123">
* MONDRIAN-1123, "ClassCastException for calculated members that are not
* part of the measures dimension"</a>.
*
* @throws java.sql.SQLException on error
*/
public void testCalcMemberInCube() throws SQLException {
final OlapConnection testContext = TestContext.instance().createSubstitutingCube("Sales", null, "<CalculatedMember name='H1 1997' formula='Aggregate([Time].[1997].[Q1]:[Time].[1997].[Q2])' dimension='Time' />").getOlap4jConnection();
final Cube cube = testContext.getOlapSchema().getCubes().get("Sales");
final List<Measure> measureList = cube.getMeasures();
StringBuilder buf = new StringBuilder();
for (Measure measure : measureList) {
buf.append(measure.getName()).append(";");
}
// Calc member in the Time dimension does not appear in the list.
// Never did, as far as I can tell.
assertEquals("Unit Sales;Store Cost;Store Sales;Sales Count;Customer Count;" + "Promotion Sales;Profit;Profit last Period;Profit Growth;", buf.toString());
final CellSet cellSet = testContext.createStatement().executeOlapQuery("select AddCalculatedMembers([Time].[Time].Members) on 0 from [Sales]");
int n = 0, n2 = 0;
for (Position position : cellSet.getAxes().get(0).getPositions()) {
if (position.getMembers().get(0).getName().equals("H1 1997")) {
++n;
}
++n2;
}
assertEquals(1, n);
assertEquals(35, n2);
final CellSet cellSet2 = testContext.createStatement().executeOlapQuery("select Filter(\n" + " AddCalculatedMembers([Time].[Time].Members),\n" + " [Time].[Time].CurrentMember.Properties('MEMBER_TYPE') = 4) on 0\n" + "from [Sales]");
n = 0;
n2 = 0;
for (Position position : cellSet2.getAxes().get(0).getPositions()) {
if (position.getMembers().get(0).getName().equals("H1 1997")) {
++n;
}
++n2;
}
assertEquals(1, n);
assertEquals(1, n2);
}