use of org.teiid.query.eval.Evaluator in project teiid by teiid.
the class TestExpressionEvaluator method helpEval.
public Object helpEval(Expression expr, Expression[] elementList, Object[] valueList, ProcessorDataManager dataMgr, CommandContext context) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
Map<Expression, Integer> elements = new HashMap<Expression, Integer>();
if (elementList != null) {
for (int i = 0; i < elementList.length; i++) {
elements.put(elementList[i], i);
}
}
List<Object> tuple = null;
if (valueList != null) {
tuple = Arrays.asList(valueList);
}
return new Evaluator(elements, dataMgr, context).evaluate(expr, tuple);
}
use of org.teiid.query.eval.Evaluator in project teiid by teiid.
the class TestProcedureResolving method testVarArgs.
@Test
public void testVarArgs() throws Exception {
String ddl = "create foreign procedure proc (x integer, VARIADIC z integer) returns (x string);\n";
TransformationMetadata tm = createMetadata(ddl);
// $NON-NLS-1$
String sql = "call proc (1, 2, 3)";
StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, 2, 3)", sp.toString());
assertEquals(new Constant(1), sp.getParameter(1).getExpression());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
// $NON-NLS-1$
sql = "call proc (1)";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1)", sp.toString());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(2).getExpression());
sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
Call call = (Call) lbf.translate(sp);
assertEquals("EXEC proc(1)", call.toString());
// $NON-NLS-1$
sql = "call proc (1, (2, 3))";
sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
assertEquals("EXEC proc(1, (2, 3))", sp.toString());
assertEquals(new Constant(1), sp.getParameter(1).getExpression());
assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
}
use of org.teiid.query.eval.Evaluator in project teiid by teiid.
the class TestSelectNode method testTimeslicing.
@Test
public void testTimeslicing() throws TeiidComponentException, TeiidProcessingException {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List elements = new ArrayList();
elements.add(es1);
CompareCriteria crit = new CompareCriteria(es1, CompareCriteria.EQ, new Constant(new Integer(1)));
List[] data = new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) };
List childElements = new ArrayList();
childElements.add(es1);
helpTestSelect(elements, crit, childElements, null, data, new FakeRelationalNode(2, data), new SelectNode(3) {
int i = 0;
@Override
protected Evaluator getEvaluator(Map elementMap) {
return new Evaluator(elementMap, getDataManager(), getContext()) {
@Override
public Boolean evaluateTVL(Criteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
if (i++ == 1) {
throw new QueryProcessor.ExpiredTimeSliceException();
}
return super.evaluateTVL(criteria, tuple);
}
};
}
});
}
use of org.teiid.query.eval.Evaluator in project teiid by teiid.
the class BatchedUpdateNode method open.
/**
* @see org.teiid.query.processor.relational.RelationalNode#open()
* @since 4.2
*/
public void open() throws TeiidComponentException, TeiidProcessingException {
super.open();
unexecutedCommands = new boolean[updateCommands.size()];
List<Command> commandsToExecute = new ArrayList<Command>(updateCommands.size());
// Find the commands to be executed
for (int i = 0; i < updateCommands.size(); i++) {
Command updateCommand = (Command) updateCommands.get(i).clone();
CommandContext context = this.getContext();
if (this.contexts != null && !this.contexts.isEmpty()) {
context = context.clone();
context.setVariableContext(this.contexts.get(i));
}
boolean needProcessing = false;
if (shouldEvaluate != null && shouldEvaluate.get(i)) {
updateCommand = (Command) updateCommand.clone();
Evaluator eval = getEvaluator(Collections.emptyMap());
eval.initialize(context, getDataManager());
AccessNode.rewriteAndEvaluate(updateCommand, eval, context, context.getMetadata());
}
needProcessing = RelationalNodeUtil.shouldExecute(updateCommand, true);
if (needProcessing) {
commandsToExecute.add(updateCommand);
} else {
unexecutedCommands[i] = true;
}
}
if (!commandsToExecute.isEmpty()) {
BatchedUpdateCommand command = new BatchedUpdateCommand(commandsToExecute);
RowBasedSecurityHelper.checkConstraints(command, getEvaluator(Collections.emptyMap()));
tupleSource = getDataManager().registerRequest(getContext(), command, modelName, new RegisterRequestParameter(null, getID(), -1));
}
}
use of org.teiid.query.eval.Evaluator in project teiid by teiid.
the class NestedTableJoinStrategy method initialize.
@Override
public void initialize(JoinNode joinNode) {
super.initialize(joinNode);
this.eval = new Evaluator(null, joinNode.getDataManager(), joinNode.getContext());
}
Aggregations