use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestGroupingNode method testBlocking.
@Test
public void testBlocking() 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) {
boolean block = true;
@Override
protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException {
if (block) {
block = false;
throw BlockedException.INSTANCE;
}
block = true;
super.closeGroup(colDiff, reset, context);
}
};
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) {
boolean end;
@Override
public List nextTuple() throws TeiidComponentException {
List result = super.nextTuple();
if (end) {
fail();
}
end = result == null;
return result;
}
};
helpProcess(mgr, node, context, expected, dataSource, null);
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestGroupingNode method testDescriptionProperties.
@Test
public void testDescriptionProperties() {
GroupingNode node = getExampleGroupingNode();
SymbolMap outputMapping = new SymbolMap();
outputMapping.addMapping(new ElementSymbol("agg0"), new AggregateSymbol("count", false, null));
node.setOutputMapping(outputMapping);
PlanNode pn = node.getDescriptionProperties();
assertTrue(pn.toString().contains("agg0=count(*)"));
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestGroupingNode method getExampleGroupingNode.
private GroupingNode getExampleGroupingNode() {
GroupingNode node = new GroupingNode(1);
List outputElements = new ArrayList();
// $NON-NLS-1$
ElementSymbol col1 = new ElementSymbol("col1");
col1.setType(Integer.class);
// $NON-NLS-1$
ElementSymbol col2 = new ElementSymbol("col2");
col2.setType(Integer.class);
outputElements.add(col1);
// $NON-NLS-1$ //$NON-NLS-2$
outputElements.add(new AggregateSymbol("COUNT", true, col2));
node.setElements(outputElements);
List groupingElements = new ArrayList();
groupingElements.add(col1);
node.setOrderBy(new OrderBy(groupingElements).getOrderByItems());
return node;
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestJoinNode method helpCreateJoin.
protected void helpCreateJoin() {
// $NON-NLS-1$
ElementSymbol es1 = new ElementSymbol("e1");
es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
// $NON-NLS-1$
ElementSymbol es2 = new ElementSymbol("e2");
es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
List leftElements = new ArrayList();
leftElements.add(es1);
leftNode = new BlockingFakeRelationalNode(1, leftTuples);
leftNode.setElements(leftElements);
List rightElements = new ArrayList();
rightElements.add(es2);
rightNode = new BlockingFakeRelationalNode(2, rightTuples) {
@Override
public boolean hasBuffer() {
return false;
}
@Override
public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
fail();
throw new AssertionError();
}
};
rightNode.setElements(rightElements);
List joinElements = new ArrayList();
joinElements.add(es1);
joinElements.add(es2);
join = new JoinNode(3);
joinStrategy = new NestedLoopJoinStrategy();
join.setJoinStrategy(joinStrategy);
join.setElements(joinElements);
join.setJoinType(joinType);
switch(criteriaType) {
case NO_CRITERIA:
break;
case EQUAL_CRITERIA:
join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es2));
joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.SORT, false);
join.setJoinStrategy(joinStrategy);
break;
case FUNCTION_CRITERIA:
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
// $NON-NLS-1$
FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
func.setFunctionDescriptor(desc);
func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
CompareCriteria joinCriteria = new CompareCriteria(es2, CompareCriteria.EQ, func);
join.setJoinCriteria(joinCriteria);
break;
}
}
use of org.teiid.query.sql.symbol.ElementSymbol in project teiid by teiid.
the class TestQueryProcessor method testProcessWithOccasionalBlocks.
@Test
public void testProcessWithOccasionalBlocks() throws Exception {
List elements = new ArrayList();
// $NON-NLS-1$
elements.add(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER));
HashSet blocked = new HashSet(Arrays.asList(new Integer[] { new Integer(0), new Integer(2), new Integer(7) }));
int numBatches = 10;
int batchRow = 1;
int rowsPerBatch = 50;
List[] expectedResults = new List[rowsPerBatch * (numBatches - blocked.size())];
List batches = new ArrayList();
for (int b = 0; b < numBatches; b++) {
if (blocked.contains(new Integer(b))) {
batches.add(BlockedException.INSTANCE);
} else {
List[] rows = new List[rowsPerBatch];
for (int i = 0; i < rowsPerBatch; i++) {
rows[i] = new ArrayList();
rows[i].add(new Integer(batchRow));
expectedResults[batchRow - 1] = rows[i];
batchRow++;
}
TupleBatch batch = new TupleBatch(batchRow - rows.length, rows);
if (b == numBatches - 1) {
batch.setTerminationFlag(true);
}
batches.add(batch);
}
}
FakeProcessorPlan plan = new FakeProcessorPlan(elements, batches);
helpTestProcessor(plan, expectedResults);
}
Aggregations