use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class ProjectNode method setSelectSymbols.
public void setSelectSymbols(List<? extends Expression> symbols) {
this.selectSymbols = symbols;
elementMap = Collections.emptyMap();
this.projectionIndexes = new int[this.selectSymbols.size()];
Arrays.fill(this.projectionIndexes, -1);
this.expressions = new ArrayList<Expression>(this.selectSymbols.size());
for (Expression ses : this.selectSymbols) {
this.expressions.add(SymbolMap.getExpression(ses));
}
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class ProjectNode method nextBatchDirect.
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (currentBatch == null) {
// one batch with one row
if (this.getChildren()[0] == null) {
currentBatch = new TupleBatch(1, EMPTY_TUPLE);
currentBatch.setTerminationFlag(true);
} else {
currentBatch = this.getChildren()[0].nextBatch();
}
// Check for no project needed and pass through
if (!needsProject) {
TupleBatch result = currentBatch;
currentBatch = null;
return result;
}
}
while (currentRow <= currentBatch.getEndRow() && !isBatchFull()) {
List<?> tuple = currentBatch.getTuple(currentRow);
List<Object> projectedTuple = new ArrayList<Object>(selectSymbols.size());
// Walk through symbols
for (int i = 0; i < expressions.size(); i++) {
Expression symbol = expressions.get(i);
updateTuple(symbol, i, tuple, projectedTuple);
}
// Add to batch
addBatchRow(projectedTuple);
currentRow++;
}
if (currentRow > currentBatch.getEndRow()) {
if (currentBatch.getTerminationFlag()) {
terminateBatches();
}
currentBatch = null;
}
return pullBatch();
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class ExecDynamicSqlInstruction method createVariableValuesMap.
/**
* @param localContext
* @return
*/
private Map<ElementSymbol, Expression> createVariableValuesMap(VariableContext localContext) {
Map<ElementSymbol, Object> variableMap = new HashMap<ElementSymbol, Object>();
localContext.getFlattenedContextMap(variableMap);
Map<ElementSymbol, Expression> nameValueMap = new HashMap<ElementSymbol, Expression>(variableMap.size());
for (Map.Entry<ElementSymbol, Object> entry : variableMap.entrySet()) {
if (entry.getKey() instanceof ElementSymbol) {
if (entry.getValue() instanceof Expression) {
nameValueMap.put(entry.getKey(), (Expression) entry.getValue());
} else {
nameValueMap.put(entry.getKey(), new Constant(entry.getValue(), entry.getKey().getType()));
}
}
}
return nameValueMap;
}
use of org.teiid.query.sql.symbol.Expression in project teiid by teiid.
the class ForEachRowPlan method nextBatch.
@Override
public TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (planContext != null) {
this.getContext().getTransactionServer().resume(planContext);
}
try {
while (true) {
if (currentTuple == null) {
if (nextTuple != null) {
currentTuple = nextTuple;
} else if (!nextNull) {
currentTuple = tupleSource.nextTuple();
}
if (currentTuple == null) {
if (this.planContext != null) {
TransactionService ts = this.getContext().getTransactionServer();
ts.commit(this.planContext);
this.planContext = null;
}
TupleBatch result = new TupleBatch(1, new List[] { Arrays.asList((int) Math.min(Integer.MAX_VALUE, updateCount)) });
result.setTerminationFlag(true);
return result;
}
}
if (first) {
TransactionContext tc = this.getContext().getTransactionContext();
if (this.planContext == null && tc != null && tc.getTransactionType() == Scope.NONE) {
Boolean txnRequired = rowProcedure.requiresTransaction(false);
boolean start = false;
if (txnRequired == null) {
nextTuple = tupleSource.nextTuple();
if (nextTuple != null) {
start = true;
} else {
nextNull = true;
}
} else if (Boolean.TRUE.equals(txnRequired)) {
start = true;
}
if (start) {
this.getContext().getTransactionServer().begin(tc);
this.planContext = tc;
}
}
first = false;
}
if (this.rowProcessor == null) {
rowProcedure.reset();
CommandContext context = getContext().clone();
this.rowProcessor = new QueryProcessor(rowProcedure, context, this.bufferMgr, this.dataMgr);
Evaluator eval = new Evaluator(lookupMap, dataMgr, context);
for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet()) {
Integer index = this.lookupMap.get(entry.getValue());
if (index != null) {
rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), this.currentTuple.get(index));
} else {
rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), eval.evaluate(entry.getValue(), this.currentTuple));
}
}
}
// save the variable context to get the key information
VariableContext vc = rowProcedure.getCurrentVariableContext();
// just getting the next batch is enough
this.rowProcessor.nextBatch();
if (insert) {
assignGeneratedKey(vc);
}
this.rowProcessor.closeProcessing();
this.rowProcessor = null;
this.currentTuple = null;
this.updateCount++;
}
} finally {
if (planContext != null) {
this.getContext().getTransactionServer().suspend(planContext);
}
}
}
use of org.teiid.query.sql.symbol.Expression 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;
}
Aggregations