Search in sources :

Example 96 with ElementSymbol

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

Example 97 with ElementSymbol

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(*)"));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) PlanNode(org.teiid.client.plan.PlanNode) SymbolMap(org.teiid.query.sql.util.SymbolMap) Test(org.junit.Test)

Example 98 with ElementSymbol

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;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) AggregateSymbol(org.teiid.query.sql.symbol.AggregateSymbol) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 99 with ElementSymbol

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;
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) TupleBuffer(org.teiid.common.buffer.TupleBuffer) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) BlockedException(org.teiid.common.buffer.BlockedException) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Function(org.teiid.query.sql.symbol.Function) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 100 with ElementSymbol

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Aggregations

ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)417 ArrayList (java.util.ArrayList)165 Test (org.junit.Test)157 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)148 Expression (org.teiid.query.sql.symbol.Expression)104 List (java.util.List)103 Constant (org.teiid.query.sql.symbol.Constant)94 MultipleElementSymbol (org.teiid.query.sql.symbol.MultipleElementSymbol)41 SymbolMap (org.teiid.query.sql.util.SymbolMap)40 PlanNode (org.teiid.query.optimizer.relational.plantree.PlanNode)36 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)29 Map (java.util.Map)28 AggregateSymbol (org.teiid.query.sql.symbol.AggregateSymbol)28 Query (org.teiid.query.sql.lang.Query)26 HashMap (java.util.HashMap)25 Select (org.teiid.query.sql.lang.Select)24 BufferManager (org.teiid.common.buffer.BufferManager)22 Criteria (org.teiid.query.sql.lang.Criteria)22 LinkedList (java.util.LinkedList)20 TupleBuffer (org.teiid.common.buffer.TupleBuffer)19