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));
}
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);
}
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();
}
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());
}
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);
}
Aggregations