Search in sources :

Example 1 with SessionAwareCache

use of org.teiid.dqp.internal.process.SessionAwareCache 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 SessionAwareCache

use of org.teiid.dqp.internal.process.SessionAwareCache in project teiid by teiid.

the class TestTempTables method testInherentUpdateUsingTemp.

@Test
public void testInherentUpdateUsingTemp() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table g1 (e1 string primary key, e2 integer, e3 boolean, e4 double, FOREIGN KEY (e1) REFERENCES G2 (e1)) options (updatable true);" + " create foreign table g2 (e1 string primary key, e2 integer, e3 boolean, e4 double) options (updatable true);" + " create view v options (updatable true) as select g2.e1, g1.e2 from g1 inner join g2 on g1.e1 = g2.e1;", "x", "pm1");
    HardcodedDataManager hdm = new HardcodedDataManager(metadata);
    setUp(metadata, hdm);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    cache.setTupleBufferCache(bm);
    dataManager = new TempTableDataManager(hdm, bm, cache);
    // $NON-NLS-1$
    execute("create temporary table x (e1 string, e2 integer, e3 string, primary key (e1))", new List[] { Arrays.asList(0) });
    execute("insert into x values ('a', 1, 'b')", new List[] { Arrays.asList(1) });
    TempMetadataID id = this.tempStore.getMetadataStore().getData().get("x");
    // ensure that we're using the actual metadata
    assertNotNull(id);
    assertNotNull(this.metadata.getPrimaryKey(id));
    hdm.addData("SELECT g_0.e1 FROM g1 AS g_0 WHERE g_0.e2 = 1", new List[] { Arrays.asList("a") });
    hdm.addData("DELETE FROM g1 WHERE g1.e1 = 'a'", new List[] { Arrays.asList(1) });
    // $NON-NLS-1$
    execute("delete from v where e2 = (select max(e2) from x as z where e3 = z.e3)", new List[] { Arrays.asList(1) }, TestOptimizer.getGenericFinder());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) TempMetadataID(org.teiid.query.metadata.TempMetadataID) BufferManager(org.teiid.common.buffer.BufferManager) CachedResults(org.teiid.dqp.internal.process.CachedResults) Test(org.junit.Test)

Example 3 with SessionAwareCache

use of org.teiid.dqp.internal.process.SessionAwareCache in project teiid by teiid.

the class TestInherintlyUpdatableViews method helpTest.

private Command helpTest(String userSql, String viewSql, String expectedSql, ProcessorDataManager dm) throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView(viewSql, metadata, "gx");
    Command command = TestQueryRewriter.helpTestRewriteCommand(userSql, expectedSql, metadata);
    if (dm != null) {
        CommandContext context = createCommandContext();
        SessionAwareCache<PreparedPlan> planCache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0);
        // $NON-NLS-1$
        context.setPreparedPlanCache(planCache);
        BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
        caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
        ProcessorPlan plan = helpGetPlan(helpParse(userSql), metadata, new DefaultCapabilitiesFinder(caps), context);
        List<?>[] expected = new List[] { Arrays.asList(1) };
        helpProcess(plan, context, dm, expected);
        assertEquals(0, planCache.getTotalCacheEntries());
    }
    return command;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)

Example 4 with SessionAwareCache

use of org.teiid.dqp.internal.process.SessionAwareCache in project teiid by teiid.

the class DQPCoreService method start.

@Override
public void start(final StartContext context) {
    this.transactionServerImpl.setWorkManager(getWorkManagerInjector().getValue());
    this.transactionServerImpl.setXaTerminator(getXaTerminatorInjector().getValue());
    this.transactionServerImpl.setTransactionManager(getTxnManagerInjector().getValue());
    this.transactionServerImpl.setDetectTransactions(true);
    setPreParser(preParserInjector.getValue());
    setAuthorizationValidator(authorizationValidatorInjector.getValue());
    this.dqpCore.setBufferManager(bufferManagerInjector.getValue());
    this.dqpCore.setTransactionService((TransactionService) LogManager.createLoggingProxy(LogConstants.CTX_TXN_LOG, transactionServerImpl, new Class[] { TransactionService.class }, MessageLevel.DETAIL, Thread.currentThread().getContextClassLoader()));
    this.dqpCore.setEventDistributor(getEventDistributorFactoryInjector().getValue().getReplicatedEventDistributor());
    this.dqpCore.setResultsetCache(getResultSetCacheInjector().getValue());
    this.dqpCore.setPreparedPlanCache(getPreparedPlanCacheInjector().getValue());
    this.dqpCore.start(this);
    // add vdb life cycle listeners
    getVdbRepository().addListener(new VDBLifeCycleListener() {

        @Override
        public void removed(String name, CompositeVDB vdb) {
            // terminate all the previous sessions
            SessionService sessionService = (SessionService) context.getController().getServiceContainer().getService(TeiidServiceNames.SESSION).getValue();
            Collection<SessionMetadata> sessions = sessionService.getSessionsLoggedInToVDB(vdb.getVDBKey());
            for (SessionMetadata session : sessions) {
                sessionService.terminateSession(session.getSessionId(), null);
            }
            // dump the caches.
            try {
                SessionAwareCache<?> value = getResultSetCacheInjector().getValue();
                if (value != null) {
                    value.clearForVDB(vdb.getVDBKey());
                }
                value = getPreparedPlanCacheInjector().getValue();
                if (value != null) {
                    value.clearForVDB(vdb.getVDBKey());
                }
            } catch (IllegalStateException e) {
            // already shutdown
            }
        }

        @Override
        public void added(String name, CompositeVDB vdb) {
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB cvdb) {
        }

        @Override
        public void beforeRemove(String name, CompositeVDB cvdb) {
        }
    });
    LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50001, this.dqpCore.getRuntimeVersion(), new Date(System.currentTimeMillis()).toString()));
}
Also used : SessionService(org.teiid.dqp.service.SessionService) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) CompositeVDB(org.teiid.deployers.CompositeVDB) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Collection(java.util.Collection) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener) Date(java.util.Date)

Example 5 with SessionAwareCache

use of org.teiid.dqp.internal.process.SessionAwareCache in project teiid by teiid.

the class TestMaterialization method setUp.

@Before
public void setUp() {
    // $NON-NLS-1$
    tempStore = new TempTableStore("1", TransactionMode.ISOLATE_WRITES);
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    TransformationMetadata actualMetadata = RealMetadataFactory.exampleMaterializedView();
    globalStore = new GlobalTableStoreImpl(bm, actualMetadata.getVdbMetaData(), actualMetadata);
    metadata = new TempMetadataAdapter(actualMetadata, tempStore.getMetadataStore());
    hdm = new HardcodedDataManager();
    hdm.addData("SELECT MatSrc.MatSrc.x FROM MatSrc.MatSrc", new List[] { Arrays.asList((String) null), Arrays.asList("one"), Arrays.asList("two"), Arrays.asList("three") });
    hdm.addData("SELECT MatTable.info.e1, MatTable.info.e2 FROM MatTable.info", new List[] { Arrays.asList("a", 1), Arrays.asList("a", 2) });
    hdm.addData("SELECT MatTable.info.e2, MatTable.info.e1 FROM MatTable.info", new List[] { Arrays.asList(1, "a"), Arrays.asList(2, "a") });
    SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    cache.setTupleBufferCache(bm);
    dataManager = new TempTableDataManager(hdm, bm, cache);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TempTableStore(org.teiid.query.tempdata.TempTableStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) BufferManager(org.teiid.common.buffer.BufferManager) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) CachedResults(org.teiid.dqp.internal.process.CachedResults) Before(org.junit.Before)

Aggregations

SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)8 CachedResults (org.teiid.dqp.internal.process.CachedResults)6 BufferManager (org.teiid.common.buffer.BufferManager)5 TempTableDataManager (org.teiid.query.tempdata.TempTableDataManager)5 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 TempTableStore (org.teiid.query.tempdata.TempTableStore)3 Test (org.junit.Test)2 PreparedPlan (org.teiid.dqp.internal.process.PreparedPlan)2 SessionService (org.teiid.dqp.service.SessionService)2 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)2 TempMetadataID (org.teiid.query.metadata.TempMetadataID)2 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)2 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 Environment (org.jboss.as.controller.access.Environment)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 BinderService (org.jboss.as.naming.service.BinderService)1