Search in sources :

Example 1 with GlobalTableStoreImpl

use of org.teiid.query.tempdata.GlobalTableStoreImpl in project teiid by teiid.

the class TestProcessor method doProcess.

public static long doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
    BufferManager bufferMgr = context.getBufferManager();
    if (bufferMgr == null) {
        BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
        bm.setProcessorBatchSize(context.getProcessorBatchSize());
        context.setBufferManager(bm);
        bufferMgr = bm;
    }
    context.getNextRand(0);
    if (context.getTempTableStore() == null) {
        context.setTempTableStore(new TempTableStore(context.getConnectionId(), TransactionMode.ISOLATE_WRITES));
    }
    if (context.getGlobalTableStore() == null) {
        GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata());
        context.setGlobalTableStore(gts);
    }
    if (!(dataManager instanceof TempTableDataManager)) {
        SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
        cache.setTupleBufferCache(bufferMgr);
        dataManager = new TempTableDataManager(dataManager, bufferMgr, cache);
    }
    if (context.getQueryProcessorFactory() == null) {
        context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
    }
    TupleBuffer id = null;
    long rowCount = 0;
    try {
        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
        // processor.setNonBlocking(true);
        BatchCollector collector = processor.createBatchCollector();
        for (int i = 0; i < 100; i++) {
            try {
                id = collector.collectTuples();
                break;
            } catch (BlockedException e) {
            }
        }
        if (id == null) {
            fail("did not complete processing");
        }
        rowCount = id.getRowCount();
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("\nResults:\n" + id.getSchema());
            TupleSource ts2 = id.createIndexedTupleSource();
            for (int j = 0; j < rowCount; j++) {
                // $NON-NLS-1$ //$NON-NLS-2$
                System.out.println("" + j + ": " + ts2.nextTuple());
            }
        }
        if (expectedResults != null) {
            examineResults(expectedResults, bufferMgr, id);
        }
    } finally {
        if (id != null) {
            id.remove();
        }
    }
    return rowCount;
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) BlockedException(org.teiid.common.buffer.BlockedException) CachedResults(org.teiid.dqp.internal.process.CachedResults) TupleSource(org.teiid.common.buffer.TupleSource) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) QueryProcessorFactoryImpl(org.teiid.dqp.internal.process.QueryProcessorFactoryImpl)

Example 2 with GlobalTableStoreImpl

use of org.teiid.query.tempdata.GlobalTableStoreImpl in project teiid by teiid.

the class TestCompositeGlobalTableStore method testCompositeGlobalTableStore.

@Test
public void testCompositeGlobalTableStore() throws VirtualDatabaseException {
    CompositeVDB vdb = TestCompositeVDB.createCompositeVDB(new MetadataStore(), "foo");
    GlobalTableStore gts = CompositeGlobalTableStore.createInstance(vdb, BufferManagerFactory.getStandaloneBufferManager(), null);
    assertTrue(gts instanceof GlobalTableStoreImpl);
    vdb.children = new LinkedHashMap<VDBKey, CompositeVDB>();
    MetadataStore ms = new MetadataStore();
    Schema s = new Schema();
    s.setName("x");
    ms.addSchema(s);
    CompositeVDB imported = TestCompositeVDB.createCompositeVDB(ms, "foo");
    GlobalTableStore gts1 = Mockito.mock(GlobalTableStore.class);
    imported.getVDB().addAttchment(GlobalTableStore.class, gts1);
    vdb.getChildren().put(new VDBKey("foo1", 1), imported);
    CompositeGlobalTableStore cgts = (CompositeGlobalTableStore) CompositeGlobalTableStore.createInstance(vdb, BufferManagerFactory.getStandaloneBufferManager(), null);
    assertEquals(gts1, cgts.getStoreForTable(RelationalPlanner.MAT_PREFIX + "X.Y"));
    assertEquals(cgts.getPrimary(), cgts.getStore("Z"));
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) Schema(org.teiid.metadata.Schema) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) Test(org.junit.Test)

Example 3 with GlobalTableStoreImpl

use of org.teiid.query.tempdata.GlobalTableStoreImpl in project teiid by teiid.

the class CommandContext method getSessionScopedStore.

public GlobalTableStoreImpl getSessionScopedStore(boolean create) {
    GlobalTableStoreImpl impl = getSession().getAttachment(GlobalTableStoreImpl.class);
    if (!create) {
        return impl;
    }
    impl = getSession().getAttachment(GlobalTableStoreImpl.class);
    if (impl == null) {
        impl = new GlobalTableStoreImpl(getBufferManager(), null, getMetadata());
        getSession().addAttchment(GlobalTableStoreImpl.class, impl);
    }
    return impl;
}
Also used : GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl)

Example 4 with GlobalTableStoreImpl

use of org.teiid.query.tempdata.GlobalTableStoreImpl in project teiid by teiid.

the class TestMaterialization method testDefaultMaterialization.

@Test
public void testDefaultMaterialization() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT * from vgroup2";
    TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    CommandContext cc = new CommandContext();
    GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata);
    cc.setGlobalTableStore(gts);
    ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc);
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT #MAT_MATVIEW.VGROUP2.x FROM #MAT_MATVIEW.VGROUP2" }, plan);
    Collection<Annotation> annotations = analysis.getAnnotations();
    // $NON-NLS-1$
    assertNotNull("Expected annotations but got none", annotations);
    // $NON-NLS-1$
    assertEquals("Expected one annotation", 1, annotations.size());
    // $NON-NLS-1$
    assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Annotation(org.teiid.client.plan.Annotation) Test(org.junit.Test)

Example 5 with GlobalTableStoreImpl

use of org.teiid.query.tempdata.GlobalTableStoreImpl in project teiid by teiid.

the class TestMaterialization method testDefaultMaterializationWithCacheHint.

@Test
public void testDefaultMaterializationWithCacheHint() throws Exception {
    // $NON-NLS-1$
    String userSql = "SELECT * from vgroup4";
    TransformationMetadata metadata = RealMetadataFactory.exampleMaterializedView();
    AnalysisRecord analysis = new AnalysisRecord(true, DEBUG);
    Command command = helpGetCommand(userSql, metadata, null);
    CommandContext cc = new CommandContext();
    GlobalTableStoreImpl gts = new GlobalTableStoreImpl(null, metadata.getVdbMetaData(), metadata);
    cc.setGlobalTableStore(gts);
    ProcessorPlan plan = TestOptimizer.getPlan(command, metadata, getGenericFinder(), analysis, true, cc);
    TestOptimizer.checkAtomicQueries(new String[] { "SELECT #MAT_MATVIEW.VGROUP4.x FROM #MAT_MATVIEW.VGROUP4" }, plan);
    Collection<Annotation> annotations = analysis.getAnnotations();
    // $NON-NLS-1$
    assertNotNull("Expected annotations but got none", annotations);
    // $NON-NLS-1$
    assertEquals("Expected one annotation", 1, annotations.size());
    // $NON-NLS-1$
    assertEquals("Expected catagory mat view", annotations.iterator().next().getCategory(), Annotation.MATERIALIZED_VIEW);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) Annotation(org.teiid.client.plan.Annotation) Test(org.junit.Test)

Aggregations

GlobalTableStoreImpl (org.teiid.query.tempdata.GlobalTableStoreImpl)9 Test (org.junit.Test)5 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)4 Annotation (org.teiid.client.plan.Annotation)3 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)3 Command (org.teiid.query.sql.lang.Command)3 CommandContext (org.teiid.query.util.CommandContext)3 BufferManager (org.teiid.common.buffer.BufferManager)2 CachedResults (org.teiid.dqp.internal.process.CachedResults)2 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)2 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)2 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)2 GlobalTableStore (org.teiid.query.tempdata.GlobalTableStore)2 TempTableDataManager (org.teiid.query.tempdata.TempTableDataManager)2 TempTableStore (org.teiid.query.tempdata.TempTableStore)2 TreeMap (java.util.TreeMap)1 Before (org.junit.Before)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 BlockedException (org.teiid.common.buffer.BlockedException)1