Search in sources :

Example 1 with Cube

use of mondrian.olap.Cube in project mondrian by pentaho.

the class ExplainPlanTest method executeOlapQuery.

private ArrayList<String> executeOlapQuery(String mdx) throws SQLException {
    OlapConnection connection = TestContext.instance().getOlap4jConnection();
    final CacheControl cacheControl = TestContext.instance().getConnection().getCacheControl(null);
    // Flush the entire cache.
    final Cube salesCube = TestContext.instance().getConnection().getSchema().lookupCube("Sales", true);
    final CacheControl.CellRegion measuresRegion = cacheControl.createMeasuresRegion(salesCube);
    cacheControl.flush(measuresRegion);
    final OlapStatement statement = connection.createStatement();
    final ArrayList<String> strings = new ArrayList<String>();
    ((mondrian.server.Statement) statement).enableProfiling(new ProfileHandler() {

        public void explain(String plan, QueryTiming timing) {
            strings.add(plan);
            strings.add(String.valueOf(timing));
        }
    });
    CellSet cellSet = statement.executeOlapQuery(mdx);
    cellSet.close();
    return strings;
}
Also used : QueryTiming(mondrian.olap.QueryTiming) OlapConnection(org.olap4j.OlapConnection) OlapStatement(org.olap4j.OlapStatement) ProfileHandler(mondrian.spi.ProfileHandler) ArrayList(java.util.ArrayList) OlapStatement(org.olap4j.OlapStatement) Cube(mondrian.olap.Cube) CacheControl(mondrian.olap.CacheControl) CellSet(org.olap4j.CellSet)

Example 2 with Cube

use of mondrian.olap.Cube in project pentaho-platform by pentaho.

the class MondrianFlushCacheComponent method executeAction.

public boolean executeAction() {
    MDXLookupRule mdxLookupRule = getLookupRule();
    Connection conn = ((MDXConnection) mdxLookupRule.shareConnection()).getConnection();
    CacheControl cacheControl = conn.getCacheControl(null);
    Cube[] cubes = conn.getSchema().getCubes();
    for (Cube cube : cubes) {
        cacheControl.flush(cacheControl.createMeasuresRegion(cube));
    }
    cacheControl.flushSchema(conn.getSchema());
    return true;
}
Also used : MDXLookupRule(org.pentaho.platform.plugin.action.mdx.MDXLookupRule) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) Cube(mondrian.olap.Cube) Connection(mondrian.olap.Connection) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) CacheControl(mondrian.olap.CacheControl)

Example 3 with Cube

use of mondrian.olap.Cube in project mondrian by pentaho.

the class SegmentCacheTest method testSegmentCacheEvents.

public void testSegmentCacheEvents() throws Exception {
    SegmentCache mockCache = new MockSegmentCache();
    SegmentCacheWorker testWorker = new SegmentCacheWorker(mockCache, null);
    // Flush the cache before we start. Wait a second for the cache
    // flush to propagate.
    final CacheControl cc = getTestContext().getConnection().getCacheControl(null);
    Cube salesCube = getCube("Sales");
    cc.flush(cc.createMeasuresRegion(salesCube));
    Thread.sleep(1000);
    MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.segmentCacheWorkers.add(testWorker);
    final List<SegmentHeader> createdHeaders = new ArrayList<SegmentHeader>();
    final List<SegmentHeader> deletedHeaders = new ArrayList<SegmentHeader>();
    final SegmentCache.SegmentCacheListener listener = new SegmentCache.SegmentCacheListener() {

        public void handle(SegmentCacheEvent e) {
            switch(e.getEventType()) {
                case ENTRY_CREATED:
                    createdHeaders.add(e.getSource());
                    break;
                case ENTRY_DELETED:
                    deletedHeaders.add(e.getSource());
                    break;
                default:
                    throw new UnsupportedOperationException();
            }
        }
    };
    try {
        // Register our custom listener.
        ((CompositeSegmentCache) MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.compositeCache).addListener(listener);
        // Now execute a query and check the events
        executeQuery("select {[Measures].[Unit Sales]} on columns from [Sales]");
        // Wait for propagation.
        Thread.sleep(2000);
        assertEquals(2, createdHeaders.size());
        assertEquals(0, deletedHeaders.size());
        assertEquals("Sales", createdHeaders.get(0).cubeName);
        assertEquals("FoodMart", createdHeaders.get(0).schemaName);
        assertEquals("Unit Sales", createdHeaders.get(0).measureName);
        createdHeaders.clear();
        deletedHeaders.clear();
        // Now flush the segment and check the events.
        cc.flush(cc.createMeasuresRegion(salesCube));
        // Wait for propagation.
        Thread.sleep(2000);
        assertEquals(0, createdHeaders.size());
        assertEquals(2, deletedHeaders.size());
        assertEquals("Sales", deletedHeaders.get(0).cubeName);
        assertEquals("FoodMart", deletedHeaders.get(0).schemaName);
        assertEquals("Unit Sales", deletedHeaders.get(0).measureName);
    } finally {
        ((CompositeSegmentCache) MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.compositeCache).removeListener(listener);
        MondrianServer.forConnection(getTestContext().getConnection()).getAggregationManager().cacheMgr.segmentCacheWorkers.remove(testWorker);
    }
}
Also used : SegmentHeader(mondrian.spi.SegmentHeader) ArrayList(java.util.ArrayList) CompositeSegmentCache(mondrian.rolap.agg.SegmentCacheManager.CompositeSegmentCache) Cube(mondrian.olap.Cube) CompositeSegmentCache(mondrian.rolap.agg.SegmentCacheManager.CompositeSegmentCache) SegmentCache(mondrian.spi.SegmentCache) CacheControl(mondrian.olap.CacheControl)

Example 4 with Cube

use of mondrian.olap.Cube in project mondrian by pentaho.

the class BatchTestCase method clearCache.

private void clearCache(RolapCube cube) {
    // Clear the cache for the Sales cube, so the query runs as if
    // for the first time. (TODO: Cleaner way to do this.)
    final Cube salesCube = getConnection().getSchema().lookupCube("Sales", true);
    RolapHierarchy hierarchy = (RolapHierarchy) salesCube.lookupHierarchy(new Id.NameSegment("Store", Id.Quoting.UNQUOTED), false);
    SmartMemberReader memberReader = (SmartMemberReader) hierarchy.getMemberReader();
    MemberCacheHelper cacheHelper = memberReader.cacheHelper;
    cacheHelper.mapLevelToMembers.cache.clear();
    cacheHelper.mapMemberToChildren.cache.clear();
    // Flush the cache, to ensure that the query gets executed.
    cube.clearCachedAggregations(true);
    CacheControl cacheControl = getConnection().getCacheControl(null);
    final CacheControl.CellRegion measuresRegion = cacheControl.createMeasuresRegion(cube);
    cacheControl.flush(measuresRegion);
    waitForFlush(cacheControl, measuresRegion, cube.getName());
}
Also used : Cube(mondrian.olap.Cube) CacheControl(mondrian.olap.CacheControl)

Example 5 with Cube

use of mondrian.olap.Cube 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);
}
Also used : Cube(mondrian.olap.Cube) Connection(mondrian.olap.Connection) Member(mondrian.olap.Member)

Aggregations

Cube (mondrian.olap.Cube)7 CacheControl (mondrian.olap.CacheControl)4 ArrayList (java.util.ArrayList)3 Member (mondrian.olap.Member)3 Connection (mondrian.olap.Connection)2 Dimension (mondrian.olap.Dimension)2 Hierarchy (mondrian.olap.Hierarchy)2 PrintWriter (java.io.PrintWriter)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 BooleanCalc (mondrian.calc.BooleanCalc)1 Calc (mondrian.calc.Calc)1 DimensionCalc (mondrian.calc.DimensionCalc)1 DoubleCalc (mondrian.calc.DoubleCalc)1 ExpCompiler (mondrian.calc.ExpCompiler)1 HierarchyCalc (mondrian.calc.HierarchyCalc)1 IntegerCalc (mondrian.calc.IntegerCalc)1 LevelCalc (mondrian.calc.LevelCalc)1 ListCalc (mondrian.calc.ListCalc)1