Search in sources :

Example 86 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestExpressionEvaluator method helpTestWithValueIterator.

private void helpTestWithValueIterator(ScalarSubquery expr, List<?> values, Object expected) throws BlockedException, TeiidComponentException, ExpressionEvaluationException {
    final CollectionValueIterator valueIter = new CollectionValueIterator(values);
    CommandContext cc = new CommandContext();
    assertEquals(expected, new Evaluator(Collections.emptyMap(), null, cc) {

        @Override
        protected ValueIterator evaluateSubquery(SubqueryContainer container, List tuple) throws TeiidProcessingException, BlockedException, TeiidComponentException {
            return valueIter;
        }
    }.evaluate(expr, null));
}
Also used : SubqueryContainer(org.teiid.query.sql.lang.SubqueryContainer) CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) List(java.util.List) CollectionValueIterator(org.teiid.query.sql.lang.CollectionValueIterator) Evaluator(org.teiid.query.eval.Evaluator)

Example 87 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestExpressionEvaluator method helpTestCommandPayload.

public void helpTestCommandPayload(Serializable payload, String property, String expectedValue) throws Exception {
    // $NON-NLS-1$
    Function func = new Function("commandpayload", new Expression[] {});
    Class[] parameterSignature = null;
    if (property == null) {
        parameterSignature = new Class[] {};
    } else {
        parameterSignature = new Class[] { String.class };
    }
    // $NON-NLS-1$
    FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("commandpayload", parameterSignature);
    func.setFunctionDescriptor(desc);
    FakeDataManager dataMgr = new FakeDataManager();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    CommandContext context = new CommandContext(null, "user", payload, "vdb", 1, false);
    if (property != null) {
        func.setArgs(new Expression[] { new Constant(property) });
    }
    String actual = (String) new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList());
    assertEquals(expectedValue, actual);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Evaluator(org.teiid.query.eval.Evaluator)

Example 88 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestProcErrors method testNestedBeginAtomicException.

@Test
public void testNestedBeginAtomicException() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String query = "BEGIN atomic\n" + " declare string VARIABLES.RESULT;\n" + " begin atomic select 1/0; exception e end end";
    ProcessorPlan plan = getProcedurePlan(query, tm);
    // Create expected results
    List<?>[] expected = new List[0];
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
    context.setMetadata(metadata);
    TransactionContext tc = new TransactionContext();
    Transaction txn = Mockito.mock(Transaction.class);
    tc.setTransaction(txn);
    tc.setTransactionType(Scope.REQUEST);
    TransactionService ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    TestProcessor.helpProcess(plan, context, new HardcodedDataManager(), expected);
    Mockito.verify(txn, Mockito.times(3)).setRollbackOnly();
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) TransactionService(org.teiid.dqp.service.TransactionService) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Transaction(javax.transaction.Transaction) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Example 89 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestAccessNode method testExecCount.

@Test
public void testExecCount() throws Exception {
    // Setup
    AccessNode node = new AccessNode(1);
    // $NON-NLS-1$
    Query query = (Query) TestResolver.helpResolve("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5", RealMetadataFactory.example1Cached());
    node.setCommand(query);
    CommandContext context = new CommandContext();
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    node.setElements(query.getProjectedSymbols());
    node.initialize(context, bm, dataManager);
    // Call open()
    node.open();
    // $NON-NLS-1$
    assertEquals(Arrays.asList("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5"), dataManager.getQueries());
}
Also used : Query(org.teiid.query.sql.lang.Query) CommandContext(org.teiid.query.util.CommandContext) FakeDataManager(org.teiid.query.processor.FakeDataManager) BufferManager(org.teiid.common.buffer.BufferManager) Test(org.junit.Test)

Example 90 with CommandContext

use of org.teiid.query.util.CommandContext in project teiid by teiid.

the class TestGroupingNode method testDefect5769.

@Test
public void testDefect5769() throws Exception {
    BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager();
    // $NON-NLS-1$
    ElementSymbol bigDecimal = new ElementSymbol("value");
    bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
    // Set up
    GroupingNode node = new GroupingNode(1);
    List outputElements = new ArrayList();
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("SUM", false, bigDecimal));
    // $NON-NLS-1$ //$NON-NLS-2$
    outputElements.add(new AggregateSymbol("AVG", false, bigDecimal));
    node.setElements(outputElements);
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    List[] data = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { new BigDecimal("0.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new BigDecimal("1.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new BigDecimal("2.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new BigDecimal("3.0") }), // $NON-NLS-1$
    Arrays.asList(new Object[] { new BigDecimal("4.0") }) };
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { new BigDecimal("10.0"), new BigDecimal("2.0") }) };
    List symbols = new ArrayList();
    symbols.add(bigDecimal);
    FakeTupleSource dataSource = new FakeTupleSource(symbols, data);
    helpProcess(mgr, node, context, expected, dataSource, null);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) CommandContext(org.teiid.query.util.CommandContext) ArrayList(java.util.ArrayList) FakeTupleSource(org.teiid.query.processor.FakeTupleSource) ArrayList(java.util.ArrayList) List(java.util.List) BufferManager(org.teiid.common.buffer.BufferManager) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

CommandContext (org.teiid.query.util.CommandContext)257 Test (org.junit.Test)179 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)104 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)95 List (java.util.List)90 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)64 ArrayList (java.util.ArrayList)44 Command (org.teiid.query.sql.lang.Command)38 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)37 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)33 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)26 Options (org.teiid.query.util.Options)20 BufferManager (org.teiid.common.buffer.BufferManager)19 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)19 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)18 TeiidProcessingException (org.teiid.core.TeiidProcessingException)14 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)13 BlockedException (org.teiid.common.buffer.BlockedException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)11 Table (org.teiid.metadata.Table)11