Search in sources :

Example 11 with AtomicRequestMessage

use of org.teiid.dqp.message.AtomicRequestMessage in project teiid by teiid.

the class DQPCore method buildRequestInfos.

private List<RequestMetadata> buildRequestInfos(Collection<RequestID> ids, long longRunningQueryThreshold) {
    List<RequestMetadata> results = new ArrayList<RequestMetadata>();
    for (RequestID requestID : ids) {
        RequestWorkItem holder = requests.get(requestID);
        if (holder != null && !holder.isCanceled() && (longRunningQueryThreshold == -1 || holder.getProcessingTimestamp() < longRunningQueryThreshold)) {
            RequestMetadata req = new RequestMetadata();
            req.setExecutionId(holder.requestID.getExecutionID());
            req.setSessionId(holder.requestID.getConnectionID());
            req.setCommand(holder.requestMsg.getCommandString());
            req.setStartTime(holder.getProcessingTimestamp());
            req.setState(holder.isCanceled() ? ProcessingState.CANCELED : (holder.isDoneProcessing() || holder.isCloseRequested()) ? ProcessingState.DONE : ProcessingState.PROCESSING);
            switch(holder.getThreadState()) {
                case DONE:
                case IDLE:
                    req.setThreadState(ThreadState.IDLE);
                    break;
                default:
                    if (holder.isProcessing()) {
                        req.setThreadState(ThreadState.RUNNING);
                    } else {
                        req.setThreadState(ThreadState.QUEUED);
                    }
            }
            if (holder.getTransactionContext() != null && holder.getTransactionContext().getTransactionType() != Scope.NONE) {
                req.setTransactionId(holder.getTransactionContext().getTransactionId());
            }
            for (DataTierTupleSource conInfo : holder.getConnectorRequests()) {
                String connectorName = conInfo.getConnectorName();
                if (connectorName == null) {
                    continue;
                }
                // If the request has not yet completed processing, then
                // add all the subrequest messages
                AtomicRequestMessage arm = conInfo.getAtomicRequestMessage();
                RequestMetadata info = new RequestMetadata();
                if (conInfo.isQueued()) {
                    info.setThreadState(ThreadState.QUEUED);
                } else if (conInfo.isRunning()) {
                    info.setThreadState(ThreadState.RUNNING);
                } else {
                    info.setThreadState(ThreadState.IDLE);
                }
                info.setExecutionId(arm.getRequestID().getExecutionID());
                info.setSessionId(holder.requestID.getConnectionID());
                info.setCommand(arm.getCommand().toString());
                info.setStartTime(arm.getProcessingTimestamp());
                info.setSourceRequest(true);
                info.setNodeId(arm.getAtomicRequestID().getNodeID());
                info.setState(conInfo.isCanceled() ? ProcessingState.CANCELED : conInfo.isDone() ? ProcessingState.DONE : ProcessingState.PROCESSING);
                results.add(info);
            }
            results.add(req);
        }
    }
    return results;
}
Also used : RequestID(org.teiid.dqp.message.RequestID) ArrayList(java.util.ArrayList) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMetadata(org.teiid.adminapi.impl.RequestMetadata)

Example 12 with AtomicRequestMessage

use of org.teiid.dqp.message.AtomicRequestMessage in project teiid by teiid.

the class TestConnectorWorkItem method testLobs.

@Test
public void testLobs() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            return new ResultSetExecution() {

                private boolean returned;

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (returned) {
                        return null;
                    }
                    returned = true;
                    return result;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    ef.setCopyLobs(true);
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] resutls = message.getResults();
    List<?> tuple = resutls[0];
    ClobType clob = (ClobType) tuple.get(0);
    assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
    assertTrue(message.supportsImplicitClose());
    result.set(0, AutoGenDataService.CLOB_VAL);
    ef.setCopyLobs(false);
    cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    message = cwi.more();
    resutls = message.getResults();
    tuple = resutls[0];
    clob = (ClobType) tuple.get(0);
    assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
    assertFalse(message.supportsImplicitClose());
    result.set(0, new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(new byte[0]);
        }

        @Override
        public StorageMode getStorageMode() {
            // TODO: introduce an explicit streaming
            return StorageMode.FREE;
        }
    }, -1));
    requestMsg.setCopyStreamingLobs(true);
    cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    message = cwi.more();
    resutls = message.getResults();
    tuple = resutls[0];
    clob = (ClobType) tuple.get(0);
    // switched from FREE to PERSISTENT
    assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
    assertFalse(message.supportsImplicitClose());
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) List(java.util.List) ArrayList(java.util.ArrayList) QueryExpression(org.teiid.language.QueryExpression) ClobImpl(org.teiid.core.types.ClobImpl) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 13 with AtomicRequestMessage

use of org.teiid.dqp.message.AtomicRequestMessage in project teiid by teiid.

the class TestConnectorWorkItem method helpExecuteUpdate.

private AtomicResultsMessage helpExecuteUpdate(boolean batch, boolean single) throws Exception, Throwable {
    // $NON-NLS-1$
    Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT);
    if (batch) {
        command = new BatchedUpdateCommand(Arrays.asList(command, command));
    }
    AtomicRequestMessage arm = createNewAtomicRequestMessage(1, 1);
    arm.setCommand(command);
    ConnectorManager connectorManager = TestConnectorManager.getConnectorManager();
    ((FakeConnector) connectorManager.getExecutionFactory()).setReturnSingleUpdate(single);
    ConnectorWorkItem synchConnectorWorkItem = new ConnectorWorkItem(arm, connectorManager);
    synchConnectorWorkItem.execute();
    return synchConnectorWorkItem.more();
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Example 14 with AtomicRequestMessage

use of org.teiid.dqp.message.AtomicRequestMessage in project teiid by teiid.

the class TestConnectorWorkItem method testIsImmutablePropertySucceeds.

@Ignore
@Test
public void testIsImmutablePropertySucceeds() throws Exception {
    /*
    	 * Setup:
    	 *  1. requestMsg.isTransactional() must be TRUE 
    	 *  2. manager.isXa() must be FALSE  ()
    	 *  3. command must NOT be a SELECT
    	 *  4. Then, set isImmutable to TRUE, we should SUCCEED
    	 */
    ConnectorManager cm = TestConnectorManager.getConnectorManager();
    ((FakeConnector) cm.getExecutionFactory()).setImmutable(true);
    // command must not be a SELECT
    // $NON-NLS-1$
    Command command = helpGetCommand("update bqt1.smalla set stringkey = 1 where stringkey = 2", EXAMPLE_BQT);
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    requestMsg.setCommand(command);
    // To make the AtomicRequestMessage transactional, construct your own
    requestMsg.setTransactionContext(new TransactionContext() {

        @Override
        public Xid getXid() {
            return Mockito.mock(Xid.class);
        }
    });
    new ConnectorWorkItem(requestMsg, cm);
}
Also used : Xid(javax.transaction.xa.Xid) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) TransactionContext(org.teiid.dqp.service.TransactionContext) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with AtomicRequestMessage

use of org.teiid.dqp.message.AtomicRequestMessage in project teiid by teiid.

the class TestConnectorWorkItem method createNewAtomicRequestMessage.

static AtomicRequestMessage createNewAtomicRequestMessage(int requestid, int nodeid) throws Exception {
    RequestMessage rm = new RequestMessage();
    DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(EXAMPLE_BQT, RealMetadataFactory.exampleBQTVDB());
    workContext.getSession().setSessionId(String.valueOf(1));
    // $NON-NLS-1$
    workContext.getSession().setUserName("foo");
    AtomicRequestMessage request = new AtomicRequestMessage(rm, workContext, nodeid);
    // $NON-NLS-1$
    request.setCommand(helpGetCommand("SELECT BQT1.SmallA.INTKEY FROM BQT1.SmallA", EXAMPLE_BQT));
    request.setRequestID(new RequestID(requestid));
    // $NON-NLS-1$
    request.setConnectorName("testing");
    request.setFetchSize(5);
    request.setCommandContext(new CommandContext());
    return request;
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) RequestID(org.teiid.dqp.message.RequestID) CommandContext(org.teiid.query.util.CommandContext) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Aggregations

AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)18 Test (org.junit.Test)9 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)8 Command (org.teiid.query.sql.lang.Command)8 RequestMessage (org.teiid.client.RequestMessage)5 RequestID (org.teiid.dqp.message.RequestID)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 BufferManager (org.teiid.common.buffer.BufferManager)3 AtomicResultsMessage (org.teiid.dqp.message.AtomicResultsMessage)3 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 Xid (javax.transaction.xa.Xid)2 Ignore (org.junit.Ignore)2 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)2 TransactionContext (org.teiid.dqp.service.TransactionContext)2 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)2 CommandContext (org.teiid.query.util.CommandContext)2 ExecutionContext (org.teiid.translator.ExecutionContext)2 ExecutionFactory (org.teiid.translator.ExecutionFactory)2