Search in sources :

Example 1 with TempTableStore

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

the class RelationalPlan method initialize.

/**
 * @see ProcessorPlan#connectDataManager(ProcessorDataManager)
 */
public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) {
    if (this.with != null) {
        context = context.clone();
        tempTableStore = new TempTableStore(context.getConnectionId(), TransactionMode.NONE);
        tempTableStore.setParentTempTableStore(context.getTempTableStore());
        context.setTempTableStore(tempTableStore);
    }
    setContext(context);
    connectExternal(this.root, context, dataMgr, bufferMgr);
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore)

Example 2 with TempTableStore

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

the class ProcedurePlan method push.

public void push(Program program) throws XATransactionException {
    this.evaluator.close();
    program.reset(this.getContext().getConnectionId());
    program.setTrappingExceptions(program.getExceptionGroup() != null || (!this.programs.isEmpty() && this.programs.peek().isTrappingExceptions()));
    TempTableStore tts = getTempTableStore();
    getContext().setTempTableStore(program.getTempTableStore());
    program.getTempTableStore().setParentTempTableStore(tts);
    this.programs.push(program);
    VariableContext context = new VariableContext(true);
    context.setParentContext(this.currentVarContext);
    this.currentVarContext = context;
    VariableContext cc = new VariableContext(true);
    cc.setParentContext(this.cursorStates);
    this.cursorStates = cc;
    if (program.isAtomic() && this.blockContext == null) {
        TransactionContext tc = this.getContext().getTransactionContext();
        if (tc != null && tc.getTransactionType() == Scope.NONE && Boolean.TRUE.equals(program.instructionsRequireTransaction(false))) {
            // start a transaction
            this.getContext().getTransactionServer().begin(tc);
            this.blockContext = tc;
            program.setStartedTxn(true);
        }
    }
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore) TransactionContext(org.teiid.dqp.service.TransactionContext) VariableContext(org.teiid.query.sql.util.VariableContext)

Example 3 with TempTableStore

use of org.teiid.query.tempdata.TempTableStore 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 4 with TempTableStore

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

the class MetaDataProcessor method processMessage.

/**
 * Process a metadata request message - this is typically either a request
 * for metadata for a prepared statement or a request for full metadata from
 * an already processed command.
 * @param metadataMsg The message from the client
 * @return The message for the client
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
MetadataResult processMessage(RequestID requestId, DQPWorkContext workContext, String preparedSql, boolean allowDoubleQuotedVariable) throws TeiidComponentException, TeiidProcessingException {
    this.requestID = requestId;
    this.metadata = workContext.getVDB().getAttachment(QueryMetadataInterface.class);
    RequestWorkItem workItem = null;
    try {
        workItem = requestManager.getRequestWorkItem(requestID);
    } catch (TeiidProcessingException e) {
        if (preparedSql == null) {
            throw e;
        }
    }
    TempTableStore tempTableStore = null;
    if (requestManager != null) {
        ClientState state = requestManager.getClientState(workContext.getSessionId(), false);
        if (state != null) {
            tempTableStore = state.sessionTables;
        }
    }
    if (tempTableStore != null) {
        metadata = new TempMetadataAdapter(this.metadata, tempTableStore.getMetadataStore());
    }
    if (workItem != null) {
        return getMetadataForCommand(workItem.getOriginalCommand());
    }
    return obtainMetadataForPreparedSql(preparedSql, workContext, allowDoubleQuotedVariable);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TempTableStore(org.teiid.query.tempdata.TempTableStore) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 5 with TempTableStore

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

the class ProcedurePlan method pop.

/**
 * @param success
 * @throws TeiidComponentException
 * @throws XATransactionException
 */
public void pop(boolean success) throws TeiidComponentException {
    this.evaluator.close();
    Program program = this.programs.pop();
    VariableContext vc = this.currentVarContext;
    VariableContext cs = this.cursorStates;
    try {
        this.currentVarContext = this.currentVarContext.getParentContext();
        this.cursorStates = this.cursorStates.getParentContext();
        TempTableStore tempTableStore = program.getTempTableStore();
        this.getContext().setTempTableStore(tempTableStore.getParentTempTableStore());
        tempTableStore.removeTempTables();
        if (program.startedTxn()) {
            TransactionService ts = this.getContext().getTransactionServer();
            TransactionContext tc = this.blockContext;
            this.blockContext = null;
            try {
                ts.resume(tc);
                for (WeakReference<DataTierTupleSource> ref : txnTupleSources) {
                    DataTierTupleSource dtts = ref.get();
                    if (dtts != null) {
                        dtts.fullyCloseSource();
                    }
                }
                this.txnTupleSources.clear();
                if (success) {
                    ts.commit(tc);
                } else {
                    ts.rollback(tc);
                }
            } catch (XATransactionException e) {
                throw new TeiidComponentException(QueryPlugin.Event.TEIID30165, e);
            }
        }
    } finally {
        removeAllCursors(cs);
    }
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore) TransactionService(org.teiid.dqp.service.TransactionService) TransactionContext(org.teiid.dqp.service.TransactionContext) DataTierTupleSource(org.teiid.dqp.internal.process.DataTierTupleSource) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException) VariableContext(org.teiid.query.sql.util.VariableContext)

Aggregations

TempTableStore (org.teiid.query.tempdata.TempTableStore)8 CachedResults (org.teiid.dqp.internal.process.CachedResults)3 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)3 TempMetadataAdapter (org.teiid.query.metadata.TempMetadataAdapter)3 TempTableDataManager (org.teiid.query.tempdata.TempTableDataManager)3 BufferManager (org.teiid.common.buffer.BufferManager)2 TransactionContext (org.teiid.dqp.service.TransactionContext)2 VariableContext (org.teiid.query.sql.util.VariableContext)2 GlobalTableStoreImpl (org.teiid.query.tempdata.GlobalTableStoreImpl)2 Before (org.junit.Before)1 XATransactionException (org.teiid.client.xa.XATransactionException)1 BlockedException (org.teiid.common.buffer.BlockedException)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 TupleSource (org.teiid.common.buffer.TupleSource)1 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 DataTierTupleSource (org.teiid.dqp.internal.process.DataTierTupleSource)1 QueryProcessorFactoryImpl (org.teiid.dqp.internal.process.QueryProcessorFactoryImpl)1 TransactionService (org.teiid.dqp.service.TransactionService)1