Search in sources :

Example 36 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestAsyncTupleSource method testTupleSource.

@Test
public void testTupleSource() throws TeiidComponentException, TeiidProcessingException {
    AsyncTupleSource ats = new AsyncTupleSource(new Callable<TupleSource>() {

        @Override
        public TupleSource call() throws Exception {
            return new CollectionTupleSource(Arrays.asList(Arrays.asList(1), Arrays.asList(2)).iterator());
        }
    }, new CommandContext());
    for (int i = 0; i < 20; i++) {
        try {
            assertEquals(Arrays.asList(1), ats.nextTuple());
            break;
        } catch (BlockedException e) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e1) {
            }
        }
    }
    assertEquals(Arrays.asList(2), ats.nextTuple());
    assertNull(ats.nextTuple());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) BlockedException(org.teiid.common.buffer.BlockedException) BlockedException(org.teiid.common.buffer.BlockedException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 37 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class BaseQueryTest method doProcess.

protected void doProcess(QueryMetadataInterface metadata, String sql, CapabilitiesFinder capFinder, ProcessorDataManager dataManager, List[] expectedResults, boolean debug) throws Exception {
    CommandContext context = createCommandContext();
    BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
    bm.setProcessorBatchSize(context.getProcessorBatchSize());
    context.setBufferManager(bm);
    doProcess(metadata, sql, capFinder, dataManager, expectedResults, debug, context);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl)

Example 38 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class Request method createCommandContext.

protected void createCommandContext() {
    if (this.context != null) {
        return;
    }
    // Create command context, used in rewriting, planning, and processing
    // Identifies a "group" of requests on a per-connection basis to allow later
    // cleanup of all resources in the group on connection shutdown
    String groupName = workContext.getSessionId();
    this.context = new CommandContext(groupName, workContext.getUserName(), requestMsg.getExecutionPayload(), workContext.getVdbName(), workContext.getVdbVersion(), this.requestMsg.getShowPlan() != ShowPlan.OFF || LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE));
    this.context.setProcessorBatchSize(bufferManager.getProcessorBatchSize());
    this.context.setGlobalTableStore(this.globalTables);
    boolean autoCleanLobs = true;
    if (this.workContext.getSession().isEmbedded()) {
        Object value = this.workContext.getSession().getSessionVariables().get(CLEAN_LOBS_ONCLOSE);
        if (value != null) {
            value = DataTypeManager.convertToRuntimeType(value, false);
            try {
                value = DataTypeManager.transformValue(value, value.getClass(), DataTypeManager.DefaultDataClasses.BOOLEAN);
                if (!(Boolean) value) {
                    autoCleanLobs = false;
                }
            } catch (TransformationException e) {
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_DQP, e, "Improper value for", CLEAN_LOBS_ONCLOSE);
            }
        }
    }
    if (!autoCleanLobs) {
        context.disableAutoCleanLobs();
    }
    context.setExecutor(this.executor);
    context.setAuthoriziationValidator(authorizationValidator);
    context.setTempTableStore(tempTableStore);
    context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(this.bufferManager, this.processorDataManager, this.capabilitiesFinder, idGenerator, metadata));
    context.setMetadata(this.metadata);
    context.setBufferManager(this.bufferManager);
    context.setPreparedPlanCache(planCache);
    context.setResultSetCacheEnabled(this.resultSetCacheEnabled);
    context.setUserRequestSourceConcurrency(this.userRequestConcurrency);
    context.setSubject(workContext.getSubject());
    this.context.setOptions(options);
    this.context.setSession(workContext.getSession());
    this.context.setRequestId(this.requestId);
    this.context.setDQPWorkContext(this.workContext);
    this.context.setTransactionService(this.transactionService);
    this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
}
Also used : TransformationException(org.teiid.core.types.TransformationException) CommandContext(org.teiid.query.util.CommandContext)

Example 39 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class QueryProcessorFactoryImpl method createQueryProcessor.

@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
    CommandContext copy = commandContext.clone();
    copy.resetDeterminismLevel(true);
    copy.setDataObjects(null);
    QueryMetadataInterface metadata = commandContext.getMetadata();
    if (metadata == null) {
        metadata = defaultMetadata;
    }
    PreparedPlan pp = getPreparedPlan(query, recursionGroup, copy, metadata);
    copy.pushVariableContext(new VariableContext());
    PreparedStatementRequest.resolveParameterValues(pp.getReferences(), Arrays.asList(params), copy, metadata);
    return new QueryProcessor(pp.getPlan().clone(), copy, bufferMgr, dataMgr);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) VariableContext(org.teiid.query.sql.util.VariableContext) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 40 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class BufferManagerImpl method releaseBuffers.

private void releaseBuffers(long count, boolean updateContext) {
    if (count < 1) {
        return;
    }
    if (updateContext) {
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
            // $NON-NLS-1$
            LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Releasing buffer space", count);
        }
        CommandContext context = CommandContext.getThreadLocalContext();
        if (context != null) {
            context.addAndGetReservedBuffers((int) -count);
        }
    } else {
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.INFO)) {
            // $NON-NLS-1$
            LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Releasing orphaned buffer space", count);
        }
    }
    lock.lock();
    try {
        this.reserveBatchBytes.addAndGet(count);
        batchesFreed.signalAll();
    } finally {
        lock.unlock();
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11