Search in sources :

Example 6 with QueryProcessor

use of org.teiid.query.processor.QueryProcessor 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 7 with QueryProcessor

use of org.teiid.query.processor.QueryProcessor in project teiid by teiid.

the class DQPCore method getPlan.

public PlanNode getPlan(String sessionId, long executionId) {
    RequestID requestID = new RequestID(sessionId, executionId);
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
        // $NON-NLS-1$
        LogManager.logDetail(LogConstants.CTX_DQP, "getPlan for requestID=" + requestID);
    }
    RequestWorkItem workItem = safeGetWorkItem(requestID);
    if (workItem == null) {
        return null;
    }
    QueryProcessor qp = workItem.getProcessor();
    if (qp == null) {
        return null;
    }
    return qp.getProcessorPlan().getDescriptionProperties();
}
Also used : RequestID(org.teiid.dqp.message.RequestID) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 8 with QueryProcessor

use of org.teiid.query.processor.QueryProcessor in project teiid by teiid.

the class Request method createProcessor.

private void createProcessor() throws TeiidComponentException {
    if (this.userCommand instanceof CreateProcedureCommand && this.processPlan instanceof ProcedurePlan) {
        ((ProcedurePlan) this.processPlan).setValidateAccess(true);
    }
    this.context.setTransactionContext(getTransactionContext(true));
    this.processor = new QueryProcessor(processPlan, context, bufferManager, processorDataManager);
}
Also used : CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) ProcedurePlan(org.teiid.query.processor.proc.ProcedurePlan) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 9 with QueryProcessor

use of org.teiid.query.processor.QueryProcessor in project teiid by teiid.

the class ForEachRowPlan method open.

@Override
public void open() throws TeiidComponentException, TeiidProcessingException {
    TransactionContext tc = this.getContext().getTransactionContext();
    if (tc != null && tc.getTransactionType() == Scope.NONE && queryPlan != null && !Boolean.FALSE.equals(queryPlan.requiresTransaction(false))) {
        // start a transaction - if not each of the row plans will
        // be executed in it's own transaction, which is bad for performance
        // TODO: should probably allow non-atomic row plans
        // the parser accepts a trigger block without atomic
        // but the spec mandates it - and we treat it as atomic
        // either way
        // TODO: for non-transactional environments this will
        // trigger an error
        this.getContext().getTransactionServer().begin(tc);
        this.planContext = tc;
    }
    if (queryPlan != null) {
        queryProcessor = new QueryProcessor(queryPlan, getContext().clone(), this.bufferMgr, this.dataMgr);
        tupleSource = new BatchCollector.BatchProducerTupleSource(queryProcessor);
    }
}
Also used : TransactionContext(org.teiid.dqp.service.TransactionContext) BatchCollector(org.teiid.query.processor.BatchCollector) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Example 10 with QueryProcessor

use of org.teiid.query.processor.QueryProcessor in project teiid by teiid.

the class ProcedurePlan method executePlan.

/**
 * @param command
 * @param rsName
 * @param procAssignments
 * @param mode
 * @param usesLocalTemp - only matters in HOLD mode
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
public void executePlan(ProcessorPlan command, String rsName, Map<ElementSymbol, ElementSymbol> procAssignments, CreateCursorResultSetInstruction.Mode mode, boolean usesLocalTemp) throws TeiidComponentException, TeiidProcessingException {
    CursorState state = (CursorState) this.cursorStates.getValue(rsName);
    if (state == null || rsName == null) {
        if (this.currentState != null && this.currentState.processor.getProcessorPlan() != command) {
            // sanity check for non-deterministic paths
            removeState(this.currentState);
            this.currentState = null;
        }
        if (this.currentState == null) {
            // this may not be the first time the plan is being run
            command.reset();
            CommandContext subContext = getContext().clone();
            subContext.setVariableContext(this.currentVarContext);
            state = new CursorState();
            state.usesLocalTemp = usesLocalTemp;
            state.processor = new QueryProcessor(command, subContext, this.bufferMgr, this);
            state.ts = new BatchIterator(state.processor);
            if (mode == Mode.HOLD && procAssignments != null && state.processor.getOutputElements().size() - procAssignments.size() > 0) {
                state.resultsBuffer = bufferMgr.createTupleBuffer(state.processor.getOutputElements().subList(0, state.processor.getOutputElements().size() - procAssignments.size()), getContext().getConnectionId(), TupleSourceType.PROCESSOR);
            } else if ((this.blockContext != null || this.programs.peek().isTrappingExceptions()) && (mode == Mode.HOLD || rsName != null)) {
                state.resultsBuffer = bufferMgr.createTupleBuffer(state.processor.getOutputElements(), getContext().getConnectionId(), TupleSourceType.PROCESSOR);
            }
            this.currentState = state;
        }
        // force execution to the first batch to ensure that the plan is executed in the context of the procedure
        this.currentState.ts.hasNext();
        if (procAssignments != null) {
            // proc assignments force us to scroll through the entire results and save as we go
            while (this.currentState.ts.hasNext()) {
                if (this.currentState.currentRow != null && this.currentState.resultsBuffer != null) {
                    this.currentState.resultsBuffer.addTuple(this.currentState.currentRow.subList(0, this.currentState.resultsBuffer.getSchema().size()));
                    this.currentState.currentRow = null;
                }
                this.currentState.currentRow = this.currentState.ts.nextTuple();
            }
            // process assignments
            Assertion.assertTrue(this.currentState.currentRow != null);
            for (Map.Entry<ElementSymbol, ElementSymbol> entry : procAssignments.entrySet()) {
                if (entry.getValue() == null || !metadata.elementSupports(entry.getValue().getMetadataID(), SupportConstants.Element.UPDATE)) {
                    continue;
                }
                int index = this.currentState.processor.getOutputElements().indexOf(entry.getKey());
                getCurrentVariableContext().setValue(entry.getValue(), DataTypeManager.transformValue(this.currentState.currentRow.get(index), entry.getValue().getType()));
            }
        } else if (this.currentState.resultsBuffer != null) {
            // result should be saved, typically to respect txn semantics
            while (this.currentState.ts.hasNext()) {
                List<?> tuple = this.currentState.ts.nextTuple();
                this.currentState.resultsBuffer.addTuple(tuple);
            }
            getCurrentVariableContext().setValue(ProcedurePlan.ROWCOUNT, 0);
        } else if (mode == Mode.UPDATE) {
            List<?> t = this.currentState.ts.nextTuple();
            if (this.currentState.ts.hasNext()) {
                // $NON-NLS-1$
                throw new AssertionError("Invalid update count result - more than 1 row returned");
            }
            removeState(this.currentState);
            this.currentState = null;
            int rowCount = 0;
            if (t != null) {
                rowCount = (Integer) t.get(0);
            }
            getCurrentVariableContext().setValue(ProcedurePlan.ROWCOUNT, rowCount);
            return;
        }
        if (rsName == null && mode == Mode.NOHOLD) {
            // TODO: could set the rowcount in this case
            while (this.currentState.ts.hasNext()) {
                this.currentState.ts.nextTuple();
            }
            this.currentState = null;
            getCurrentVariableContext().setValue(ProcedurePlan.ROWCOUNT, 0);
            return;
        }
        if (this.currentState.resultsBuffer != null) {
            // close the results buffer and use a buffer backed tuplesource
            this.currentState.resultsBuffer.close();
            this.currentState.ts = this.currentState.resultsBuffer.createIndexedTupleSource(true);
        }
        CursorState old = (CursorState) this.cursorStates.setValue(rsName, this.currentState);
        if (old != null) {
            removeState(old);
        }
        this.currentState = null;
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) CommandContext(org.teiid.query.util.CommandContext) BatchIterator(org.teiid.query.processor.BatchIterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) QueryProcessor(org.teiid.query.processor.QueryProcessor)

Aggregations

QueryProcessor (org.teiid.query.processor.QueryProcessor)14 ArrayList (java.util.ArrayList)4 BatchCollector (org.teiid.query.processor.BatchCollector)4 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)4 CommandContext (org.teiid.query.util.CommandContext)4 List (java.util.List)3 Map (java.util.Map)3 TransactionContext (org.teiid.dqp.service.TransactionContext)3 Determinism (org.teiid.metadata.FunctionMethod.Determinism)3 VariableContext (org.teiid.query.sql.util.VariableContext)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)2 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 TupleBatch (org.teiid.common.buffer.TupleBatch)2 TupleBuffer (org.teiid.common.buffer.TupleBuffer)2 TupleSource (org.teiid.common.buffer.TupleSource)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2