Search in sources :

Example 1 with CachedResults

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

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

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

the class EmbeddedServer method start.

public synchronized void start(@SuppressWarnings("hiding") EmbeddedConfiguration config) {
    if (running != null) {
        throw new IllegalStateException();
    }
    this.dqp.setLocalProfile(this.embeddedProfile);
    this.shutdownListener.setBootInProgress(true);
    this.config = config;
    System.setProperty("jboss.node.name", config.getNodeName() == null ? "localhost" : config.getNodeName());
    this.cmr.setProvider(this);
    this.eventDistributorFactoryService = new EmbeddedEventDistributorFactoryService();
    this.eventDistributorFactoryService.start();
    this.dqp.setEventDistributor(this.eventDistributorFactoryService.getReplicatedEventDistributor());
    // $NON-NLS-1$
    this.scheduler = Executors.newScheduledThreadPool(config.getMaxAsyncThreads(), new NamedThreadFactory("Asynch Worker"));
    this.replicator = config.getObjectReplicator();
    if (this.replicator == null && config.getJgroupsConfigFile() != null) {
        channelFactory = new SimpleChannelFactory(config);
        this.replicator = new JGroupsObjectReplicator(channelFactory, this.scheduler);
        try {
            this.nodeTracker = new NodeTracker(channelFactory.createChannel("teiid-node-tracker"), config.getNodeName()) {

                @Override
                public ScheduledExecutorService getScheduledExecutorService() {
                    return scheduler;
                }
            };
        } catch (Exception e) {
            LogManager.logError(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
        }
    }
    this.eventDistributorFactoryService = new EmbeddedEventDistributorFactoryService();
    // must be called after the replicator is set
    this.eventDistributorFactoryService.start();
    this.dqp.setEventDistributor(this.eventDistributorFactoryService.getReplicatedEventDistributor());
    if (config.getTransactionManager() == null) {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
        this.transactionService.setTransactionManager((TransactionManager) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { TransactionManager.class }, new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw new UnsupportedOperationException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
            }
        }));
    } else {
        this.transactionService.setDetectTransactions(true);
        this.transactionService.setTransactionManager(config.getTransactionManager());
    }
    if (config.getSecurityHelper() != null) {
        this.sessionService.setSecurityHelper(config.getSecurityHelper());
    } else {
        this.sessionService.setSecurityHelper(new DoNothingSecurityHelper());
    }
    if (config.getSecurityDomain() != null) {
        this.sessionService.setSecurityDomain(config.getSecurityDomain());
    } else {
        // $NON-NLS-1$
        this.sessionService.setSecurityDomain("teiid-security");
    }
    this.sessionService.setVDBRepository(repo);
    setBufferManagerProperties(config);
    BufferService bs = getBufferService();
    this.dqp.setBufferManager(bs.getBufferManager());
    startVDBRepository();
    // $NON-NLS-1$
    rs = new SessionAwareCache<CachedResults>("resultset", config.getCacheFactory(), SessionAwareCache.Type.RESULTSET, config.getMaxResultSetCacheStaleness());
    // $NON-NLS-1$
    ppc = new SessionAwareCache<PreparedPlan>("preparedplan", config.getCacheFactory(), SessionAwareCache.Type.PREPAREDPLAN, 0);
    rs.setTupleBufferCache(bs.getTupleBufferCache());
    this.dqp.setResultsetCache(rs);
    ppc.setTupleBufferCache(bs.getTupleBufferCache());
    this.dqp.setPreparedPlanCache(ppc);
    this.dqp.setTransactionService((TransactionService) LogManager.createLoggingProxy(LogConstants.CTX_TXN_LOG, this.transactionService, new Class[] { TransactionService.class }, MessageLevel.DETAIL, Thread.currentThread().getContextClassLoader()));
    this.dqp.start(config);
    this.sessionService.setDqp(this.dqp);
    this.services.setSecurityHelper(this.sessionService.getSecurityHelper());
    if (this.config.getAuthenticationType() != null) {
        this.services.setAuthenticationType(this.config.getAuthenticationType());
        this.sessionService.setAuthenticationType(this.config.getAuthenticationType());
    }
    this.sessionService.start();
    this.services.setVDBRepository(this.repo);
    this.materializationMgr = getMaterializationManager();
    this.repo.addListener(this.materializationMgr);
    this.repo.setAllowEnvFunction(this.config.isAllowEnvFunction());
    if (this.nodeTracker != null) {
        this.nodeTracker.addNodeListener(this.materializationMgr);
    }
    this.logon = new LogonImpl(sessionService, null);
    services.registerClientService(ILogon.class, logon, LogConstants.CTX_SECURITY);
    DQP dqpProxy = DQP.class.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { DQP.class }, new SessionCheckingProxy(dqp, LogConstants.CTX_DQP, MessageLevel.TRACE)));
    services.registerClientService(DQP.class, dqpProxy, LogConstants.CTX_DQP);
    initDriver();
    List<SocketConfiguration> transports = config.getTransports();
    if (transports != null && !transports.isEmpty()) {
        for (SocketConfiguration socketConfig : transports) {
            SocketListener socketConnection = startTransport(socketConfig, bs.getBufferManager(), config.getMaxODBCLobSizeAllowed());
            if (socketConfig.getSSLConfiguration() != null) {
                try {
                    socketConfig.getSSLConfiguration().getServerSSLEngine();
                } catch (Exception e) {
                    throw new TeiidRuntimeException(e);
                }
            }
            this.transports.add(socketConnection);
        }
    }
    this.shutdownListener.setBootInProgress(false);
    this.shutdownListener.started();
    running = true;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) JGroupsObjectReplicator(org.teiid.replication.jgroups.JGroupsObjectReplicator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DQP(org.teiid.client.DQP) NamedThreadFactory(org.teiid.core.util.NamedThreadFactory) BufferService(org.teiid.dqp.service.BufferService) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) XMLStreamException(javax.xml.stream.XMLStreamException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ConnectionException(org.teiid.net.ConnectionException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) TeiidException(org.teiid.core.TeiidException) SAXException(org.xml.sax.SAXException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CachedResults(org.teiid.dqp.internal.process.CachedResults) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan)

Example 4 with CachedResults

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

the class TempTableDataManager method handleCachedProcedure.

private TupleSource handleCachedProcedure(final CommandContext context, StoredProcedure proc) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
    String fullName = context.getMetadata().getFullName(proc.getProcedureID());
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_DQP, "processing cached procedure request for", fullName);
    LinkedList<Object> vals = new LinkedList<Object>();
    for (SPParameter param : proc.getInputParameters()) {
        vals.add(((Constant) param.getExpression()).getValue());
    }
    // collapse the hash to single byte for the key to restrict the possible results to 256
    int hash = vals.hashCode();
    hash |= (hash >>> 16);
    hash |= (hash >>> 8);
    hash &= 0x000000ff;
    final CacheID cid = new CacheID(new ParseInfo(), fullName + hash, context.getVdbName(), context.getVdbVersion(), context.getConnectionId(), context.getUserName());
    cid.setParameters(vals);
    CachedResults results = cache.get(cid);
    if (results != null) {
        TupleBuffer buffer = results.getResults();
        return buffer.createIndexedTupleSource();
    }
    // construct a query with a no cache hint
    final CacheHint hint = proc.getCacheHint();
    proc.setCacheHint(null);
    Option option = new Option();
    option.setNoCache(true);
    option.addNoCacheGroup(fullName);
    proc.setOption(option);
    StoredProcedure cloneProc = (StoredProcedure) proc.clone();
    int i = 0;
    for (SPParameter param : cloneProc.getInputParameters()) {
        param.setExpression(new Reference(i++));
    }
    final QueryProcessor qp = context.getQueryProcessorFactory().createQueryProcessor(cloneProc.toString(), fullName.toUpperCase(), context, vals.toArray());
    final BatchCollector bc = qp.createBatchCollector();
    return new ProxyTupleSource() {

        boolean success = false;

        @Override
        protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException {
            TupleBuffer tb = bc.collectTuples();
            CachedResults cr = new CachedResults();
            cr.setResults(tb, qp.getProcessorPlan());
            Determinism determinismLevel = qp.getContext().getDeterminismLevel();
            if (hint != null && hint.getDeterminism() != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ", determinismLevel, " to ", hint.getDeterminism() });
                determinismLevel = hint.getDeterminism();
            }
            cache.put(cid, determinismLevel, cr, hint != null ? hint.getTtl() : null);
            context.setDeterminismLevel(determinismLevel);
            success = true;
            return tb.createIndexedTupleSource();
        }

        @Override
        public void closeSource() {
            super.closeSource();
            qp.closeProcessing();
            if (!success && bc.getTupleBuffer() != null) {
                bc.getTupleBuffer().remove();
            }
        }
    };
}
Also used : Determinism(org.teiid.metadata.FunctionMethod.Determinism) Reference(org.teiid.query.sql.symbol.Reference) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ParseInfo(org.teiid.query.parser.ParseInfo) LinkedList(java.util.LinkedList) CachedResults(org.teiid.dqp.internal.process.CachedResults) QueryProcessor(org.teiid.query.processor.QueryProcessor) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) BatchCollector(org.teiid.query.processor.BatchCollector)

Example 5 with CachedResults

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

CachedResults (org.teiid.dqp.internal.process.CachedResults)8 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)6 BufferManager (org.teiid.common.buffer.BufferManager)5 TempTableDataManager (org.teiid.query.tempdata.TempTableDataManager)5 TempTableStore (org.teiid.query.tempdata.TempTableStore)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Test (org.junit.Test)2 TupleBuffer (org.teiid.common.buffer.TupleBuffer)2 NamedThreadFactory (org.teiid.core.util.NamedThreadFactory)2 PreparedPlan (org.teiid.dqp.internal.process.PreparedPlan)2 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)2 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1