Search in sources :

Example 11 with Evaluator

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);
}
Also used : HashMap(java.util.HashMap) Evaluator(org.teiid.query.eval.Evaluator)

Example 12 with Evaluator

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());
}
Also used : Array(org.teiid.query.sql.symbol.Array) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Example 13 with Evaluator

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);
                }
            };
        }
    });
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Evaluator(org.teiid.query.eval.Evaluator) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 14 with Evaluator

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));
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter)

Example 15 with Evaluator

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());
}
Also used : Evaluator(org.teiid.query.eval.Evaluator)

Aggregations

Evaluator (org.teiid.query.eval.Evaluator)20 ArrayList (java.util.ArrayList)12 List (java.util.List)7 CommandContext (org.teiid.query.util.CommandContext)7 TeiidComponentException (org.teiid.core.TeiidComponentException)6 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)6 HashMap (java.util.HashMap)5 Map (java.util.Map)4 Test (org.junit.Test)4 Expression (org.teiid.query.sql.symbol.Expression)4 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)3 BlockedException (org.teiid.common.buffer.BlockedException)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 LanguageBridgeFactory (org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)2 Call (org.teiid.language.Call)2 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)2 FakeDataManager (org.teiid.query.processor.FakeDataManager)2