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;
}
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());
}
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;
}
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()));
}
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);
}
Aggregations