Search in sources :

Example 16 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestAllResultsImpl method testDateType.

@Test
public void testDateType() throws SQLException {
    RequestMessage request = new RequestMessage();
    request.setExecutionId(REQUEST_ID);
    ResultsMessage resultsMsg = new ResultsMessage();
    resultsMsg.setResults(new List[] { Arrays.asList(new Timestamp(0)) });
    // $NON-NLS-1$
    resultsMsg.setColumnNames(new String[] { "TS" });
    resultsMsg.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.TIMESTAMP });
    resultsMsg.setFirstRow(1);
    resultsMsg.setFinalRow(1);
    resultsMsg.setLastRow(1);
    ResultSetImpl rs = new ResultSetImpl(resultsMsg, statement);
    assertTrue(rs.next());
    // assumes the mock statement is setup with GMT-5 server and GMT-6 client
    // will adjust ahead one hour
    assertEquals(new Timestamp(3600000), rs.getObject(1));
    // will be the same as the original
    // $NON-NLS-1$
    assertEquals(new Timestamp(0), rs.getTimestamp(1, Calendar.getInstance(TimeZone.getTimeZone("GMT-05:00"))));
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 17 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class TestAllResultsImpl method exampleResultsMsg4.

static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
    RequestMessage request = new RequestMessage();
    request.setExecutionId(REQUEST_ID);
    ResultsMessage resultsMsg = new ResultsMessage();
    List[] results = exampleResults1(length, begin);
    resultsMsg.setResults(results);
    // $NON-NLS-1$
    resultsMsg.setColumnNames(new String[] { "IntKey" });
    resultsMsg.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    resultsMsg.setFirstRow(begin);
    if (lastBatch) {
        resultsMsg.setFinalRow(begin + results.length - 1);
    }
    resultsMsg.setLastRow(begin + results.length - 1);
    return resultsMsg;
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) RequestMessage(org.teiid.client.RequestMessage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class DQPCore method logMMCommand.

void logMMCommand(RequestWorkItem workItem, Event status, Long rowCount, Long cpuTime) {
    if ((status != Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.INFO)) || (status == Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE))) {
        return;
    }
    RequestMessage msg = workItem.requestMsg;
    DQPWorkContext workContext = DQPWorkContext.getWorkContext();
    RequestID rID = workItem.requestID;
    String txnID = null;
    TransactionContext tc = workItem.getTransactionContext();
    if (tc != null && tc.getTransactionType() != Scope.NONE) {
        txnID = tc.getTransactionId();
    }
    String appName = workContext.getAppName();
    // Log to request log
    CommandLogMessage message = null;
    if (status == Event.NEW) {
        message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), appName, workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), msg.getCommandString(), cpuTime);
    } else {
        QueryProcessor qp = workItem.getProcessor();
        PlanNode plan = null;
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE) && qp != null) {
            plan = qp.getProcessorPlan().getDescriptionProperties();
        }
        message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), rowCount, status, plan);
    }
    LogManager.log(status == Event.PLAN ? MessageLevel.TRACE : MessageLevel.INFO, LogConstants.CTX_COMMANDLOGGING, message);
}
Also used : PlanNode(org.teiid.client.plan.PlanNode) RequestID(org.teiid.dqp.message.RequestID) TransactionContext(org.teiid.dqp.service.TransactionContext) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) CommandLogMessage(org.teiid.logging.CommandLogMessage) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 19 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class DQPCore method executeQuery.

/**
 * Execute the given query asynchly. Has a hard limit of only returning max rows fetch size rows.
 * @param command
 * @param vdb
 * @param user
 * @param app
 * @param timeoutInMilli
 * @param engine
 * @param listener
 * @return
 * @throws Throwable
 */
public static ResultsFuture<?> executeQuery(final Object command, final VDBMetaData vdb, final String user, final String app, final long timeoutInMilli, final DQPCore engine, final ResultsListener listener) throws Throwable {
    final SessionMetadata session = TempTableDataManager.createTemporarySession(user, app, vdb);
    final long requestID = 0L;
    DQPWorkContext workContext = new DQPWorkContext();
    if (engine.localProfile != null) {
        workContext.setConnectionProfile(engine.localProfile);
    }
    workContext.setUseCallingThread(true);
    workContext.setSession(session);
    workContext.setAdmin(true);
    final ResultsFuture<Void> resultFuture = new ResultsFuture<Void>();
    resultFuture.addCompletionListener(new ResultsFuture.CompletionListener<Void>() {

        @SuppressWarnings("unchecked")
        @Override
        public void onCompletion(ResultsFuture<Void> future) {
            ResultsFuture<?> response;
            try {
                response = engine.closeRequest(requestID);
                response.addCompletionListener(new ResultsFuture.CompletionListener() {

                    @Override
                    public void onCompletion(ResultsFuture future) {
                        engine.terminateSession(session.getSessionId());
                    }
                });
            } catch (Exception e) {
                engine.terminateSession(session.getSessionId());
            }
        }
    });
    workContext.runInContext(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            RequestMessage request = new RequestMessage();
            if (command instanceof String) {
                request.setCommands((String) command);
            } else {
                request.setCommands(command.toString());
                request.setCommand(command);
            }
            request.setExecutionId(requestID);
            // this would limit the number of rows that are returned.
            request.setRowLimit(engine.getMaxRowsFetchSize());
            ResultsFuture<ResultsMessage> message = engine.executeRequest(requestID, request, timeoutInMilli);
            message.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {

                @Override
                public void onCompletion(ResultsFuture<ResultsMessage> future) {
                    try {
                        ResultsMessage rm = future.get();
                        if (rm.getException() != null) {
                            throw rm.getException();
                        }
                        if (rm.isUpdateResult()) {
                            // $NON-NLS-1$
                            listener.onResults(Arrays.asList("update-count"), rm.getResultsList());
                            resultFuture.getResultsReceiver().receiveResults(null);
                        } else {
                            processResult(rm);
                        }
                    } catch (Exception e) {
                        resultFuture.getResultsReceiver().exceptionOccurred(e);
                    }
                }

                private void processResult(ResultsMessage rm) throws Exception {
                    if (rm.getException() != null) {
                        throw rm.getException();
                    }
                    listener.onResults(Arrays.asList(rm.getColumnNames()), rm.getResultsList());
                    if (rm.getFinalRow() == -1 || rm.getLastRow() < rm.getFinalRow()) {
                        ResultsFuture<ResultsMessage> next = engine.processCursorRequest(requestID, rm.getLastRow() + 1, 1024);
                        next.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {

                            @Override
                            public void onCompletion(ResultsFuture<ResultsMessage> future) {
                                try {
                                    processResult(future.get());
                                } catch (Exception e) {
                                    resultFuture.getResultsReceiver().exceptionOccurred(e);
                                }
                            }
                        });
                    } else {
                        resultFuture.getResultsReceiver().receiveResults(null);
                    }
                }
            });
            return null;
        }
    });
    return resultFuture;
}
Also used : ResultsMessage(org.teiid.client.ResultsMessage) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) XATransactionException(org.teiid.client.xa.XATransactionException) AdminException(org.teiid.adminapi.AdminException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ResultsFuture(org.teiid.client.util.ResultsFuture) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage)

Example 20 with RequestMessage

use of org.teiid.client.RequestMessage in project teiid by teiid.

the class DQPCore method start.

public void start(DQPConfiguration theConfig) {
    this.config = theConfig;
    this.authorizationValidator = config.getAuthorizationValidator();
    this.chunkSize = config.getLobChunkSizeInKB() * 1024;
    this.processWorkerPool = config.getTeiidExecutor();
    // we don't want cancellations waiting on normal processing, so they get a small dedicated pool
    // TODO: overflow to the worker pool
    // $NON-NLS-1$
    timeoutExecutor = ExecutorUtils.newFixedThreadPool(3, "Server Side Timeout");
    this.cancellationTimer = new EnhancedTimer(timeoutExecutor, timeoutExecutor);
    this.maxActivePlans = config.getMaxActivePlans();
    if (this.maxActivePlans > config.getMaxThreads()) {
        LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30006, this.maxActivePlans, config.getMaxThreads()));
        this.maxActivePlans = config.getMaxThreads();
    }
    // for now options are scoped to the engine - vdb scoping is a todo
    options = new Options();
    options.setAssumeMatchingCollation(false);
    options.setProperties(config.getProperties());
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid", true);
    this.bufferManager.setOptions(options);
    // hack to set the max active plans
    this.bufferManager.setMaxActivePlans(this.maxActivePlans);
    try {
        this.bufferManager.initialize();
    } catch (TeiidComponentException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30496, e);
    }
    this.userRequestSourceConcurrency = config.getUserRequestSourceConcurrency();
    if (this.userRequestSourceConcurrency < 1) {
        this.userRequestSourceConcurrency = Math.min(config.getMaxThreads(), 2 * config.getMaxThreads() / this.maxActivePlans);
    }
    DataTierManagerImpl processorDataManager = new DataTierManagerImpl(this, this.bufferManager, this.config.isDetectingChangeEvents());
    processorDataManager.setEventDistributor(eventDistributor);
    dataTierMgr = new TempTableDataManager(processorDataManager, this.bufferManager, this.rsCache);
    dataTierMgr.setExecutor(new TempTableDataManager.RequestExecutor() {

        @Override
        public void execute(String command, List<?> parameters) {
            final String sessionId = DQPWorkContext.getWorkContext().getSessionId();
            RequestMessage request = new RequestMessage(command);
            request.setParameterValues(parameters);
            request.setStatementType(StatementType.PREPARED);
            ResultsFuture<ResultsMessage> result;
            try {
                result = executeRequest(0, request);
            } catch (TeiidProcessingException e) {
                throw new TeiidRuntimeException(e);
            }
            result.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {

                @Override
                public void onCompletion(ResultsFuture<ResultsMessage> future) {
                    terminateSession(sessionId);
                }
            });
        }

        @Override
        public boolean isShutdown() {
            return shutdown;
        }
    });
    dataTierMgr.setEventDistributor(eventDistributor);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    LogManager.logDetail(LogConstants.CTX_DQP, "DQPCore started maxThreads", this.config.getMaxThreads(), "maxActivePlans", this.maxActivePlans, "source concurrency", this.userRequestSourceConcurrency);
}
Also used : Options(org.teiid.query.util.Options) EnhancedTimer(org.teiid.jdbc.EnhancedTimer) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ResultsFuture(org.teiid.client.util.ResultsFuture) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) RequestMessage(org.teiid.client.RequestMessage) TeiidComponentException(org.teiid.core.TeiidComponentException)

Aggregations

RequestMessage (org.teiid.client.RequestMessage)44 ResultsMessage (org.teiid.client.ResultsMessage)23 Test (org.junit.Test)22 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)10 RequestID (org.teiid.dqp.message.RequestID)8 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)6 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)6 ResultsFuture (org.teiid.client.util.ResultsFuture)5 List (java.util.List)4 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Command (org.teiid.query.sql.lang.Command)3 TimeoutException (java.util.concurrent.TimeoutException)2 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 CommandContext (org.teiid.query.util.CommandContext)2 BatchUpdateException (java.sql.BatchUpdateException)1