Search in sources :

Example 6 with VariableContext

use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.

the class ProcedurePlan method createVariableContext.

private void createVariableContext() {
    this.currentVarContext = new VariableContext(runInContext && this.params == null);
    this.currentVarContext.setValue(ROWCOUNT, 0);
    this.cursorStates = new VariableContext(false);
    this.cursorStates.setValue(null, null);
}
Also used : VariableContext(org.teiid.query.sql.util.VariableContext)

Example 7 with VariableContext

use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.

the class ProcedurePlan method nextBatchDirect.

/**
 * @see ProcessorPlan#nextBatch()
 */
public TupleBatch nextBatchDirect() throws TeiidComponentException, TeiidProcessingException, BlockedException {
    // Already returned results?
    if (done) {
        // Already returned all results
        TupleBatch emptyTerminationBatch = new TupleBatch(beginBatch, new List[0]);
        emptyTerminationBatch.setTerminationFlag(true);
        return emptyTerminationBatch;
    }
    // First attempt to process
    if (this.finalTupleSource == null) {
        // Still need to process - this should either
        // throw a BlockedException or return a finalTupleSource
        this.finalTupleSource = processProcedure();
    }
    // Next, attempt to return batches if processing completed
    while (!isBatchFull()) {
        // May throw BlockedException and exit here
        List<?> tuple = this.finalTupleSource.nextTuple();
        if (tuple == null) {
            if (outParams != null) {
                VariableContext vc = getCurrentVariableContext();
                List<Object> paramTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
                int i = this.getOutputElements().size() - this.outParams.size();
                for (ElementSymbol param : outParams) {
                    Object value = vc.getValue(param);
                    checkNotNull(param, value);
                    paramTuple.set(i++, value);
                }
                addBatchRow(paramTuple, true);
            }
            terminateBatches();
            done = true;
            break;
        }
        addBatchRow(tuple, false);
    }
    return pullBatch();
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) VariableContext(org.teiid.query.sql.util.VariableContext) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 8 with VariableContext

use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.

the class ProcedurePlan method open.

public void open() throws TeiidProcessingException, TeiidComponentException {
    if (!this.evaluatedParams) {
        if (this.outParams != null) {
            for (ElementSymbol param : this.outParams) {
                setParameterValue(param, getCurrentVariableContext(), null);
            }
        }
        if (this.params != null) {
            for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet()) {
                ElementSymbol param = entry.getKey();
                Expression expr = entry.getValue();
                VariableContext context = getCurrentVariableContext();
                if (context.getVariableMap().containsKey(param)) {
                    continue;
                }
                Object value = this.evaluateExpression(expr);
                // check constraint
                checkNotNull(param, value);
                setParameterValue(param, context, value);
            }
            this.evaluator.close();
        } else if (runInContext) {
            // if there are no params, this needs to run in the current variable context
            this.currentVarContext.setParentContext(parentContext);
        }
        this.push(originalProgram);
    }
    this.evaluatedParams = true;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Expression(org.teiid.query.sql.symbol.Expression) VariableContext(org.teiid.query.sql.util.VariableContext) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with VariableContext

use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.

the class BatchedUpdatePlan method initialize.

/**
 * @see org.teiid.query.processor.ProcessorPlan#initialize(org.teiid.query.util.CommandContext, org.teiid.query.processor.ProcessorDataManager, org.teiid.common.buffer.BufferManager)
 * @since 4.2
 */
public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) {
    context = context.clone();
    // start a new root variable context
    context.setVariableContext(new VariableContext());
    this.setContext(context);
    // Initialize all the child plans
    for (int i = 0; i < getPlanCount(); i++) {
        updatePlans[i].initialize(context, dataMgr, bufferMgr);
    }
}
Also used : VariableContext(org.teiid.query.sql.util.VariableContext)

Example 10 with VariableContext

use of org.teiid.query.sql.util.VariableContext in project teiid by teiid.

the class BatchedUpdatePlan method openPlan.

private void openPlan() throws TeiidComponentException, TeiidProcessingException {
    // reset prior to updating the context
    updatePlans[planIndex].reset();
    if (this.contexts != null && !this.contexts.isEmpty()) {
        CommandContext context = updatePlans[planIndex].getContext();
        VariableContext vc = context.getVariableContext();
        // this is just a safe guard against the plan not correctly resetting the context
        while (vc.getParentContext() != null) {
            vc = vc.getParentContext();
        }
        vc.clear();
        VariableContext currentValues = this.contexts.get(planIndex);
        vc.putAll(currentValues);
    }
    TransactionContext tc = this.getContext().getTransactionContext();
    if (startTxn[planIndex] && tc != null && tc.getTransactionType() == Scope.NONE) {
        this.getContext().getTransactionServer().begin(tc);
        this.planContexts[planIndex] = tc;
    }
    updatePlans[planIndex].open();
    planOpened[planIndex] = true;
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TransactionContext(org.teiid.dqp.service.TransactionContext) VariableContext(org.teiid.query.sql.util.VariableContext)

Aggregations

VariableContext (org.teiid.query.sql.util.VariableContext)22 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)6 Expression (org.teiid.query.sql.symbol.Expression)6 List (java.util.List)5 TransactionContext (org.teiid.dqp.service.TransactionContext)5 CommandContext (org.teiid.query.util.CommandContext)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 QueryProcessor (org.teiid.query.processor.QueryProcessor)3 Command (org.teiid.query.sql.lang.Command)3 Constant (org.teiid.query.sql.symbol.Constant)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)2 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)2 XATransactionException (org.teiid.client.xa.XATransactionException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 TupleBatch (org.teiid.common.buffer.TupleBatch)2 TeiidComponentException (org.teiid.core.TeiidComponentException)2