Search in sources :

Example 61 with TupleBatch

use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.

the class TestEnginePerformance method helpTestLargeSort.

private void helpTestLargeSort(int iterations, int threads, final int rows) throws InterruptedException, Exception {
    final List<ElementSymbol> elems = new ArrayList<ElementSymbol>();
    final int cols = 50;
    for (int i = 0; i < cols; i++) {
        ElementSymbol elem1 = new ElementSymbol("e" + i);
        elem1.setType(DataTypeManager.DefaultDataClasses.STRING);
        elems.add(elem1);
    }
    final List<ElementSymbol> sortElements = Arrays.asList(elems.get(0));
    final Task task = new Task() {

        @Override
        public Void call() throws Exception {
            // $NON-NLS-1$ //$NON-NLS-2$
            CommandContext context = new CommandContext("pid", "test", null, null, 1);
            SortNode sortNode = new SortNode(1);
            sortNode.setSortElements(new OrderBy(sortElements).getOrderByItems());
            sortNode.setMode(Mode.SORT);
            sortNode.setElements(elems);
            RelationalNode rn = new RelationalNode(2) {

                int blockingPeriod = 3;

                int count = 0;

                int batches = 0;

                @Override
                protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
                    if (count++ % blockingPeriod == 0) {
                        throw BlockedException.INSTANCE;
                    }
                    int batchSize = this.getBatchSize();
                    int batchRows = batchSize;
                    boolean done = false;
                    int start = batches++ * batchSize;
                    if (start + batchSize >= rows) {
                        done = true;
                        batchRows = rows - start;
                    }
                    ArrayList<List<?>> batch = new ArrayList<List<?>>(batchRows);
                    for (int i = 0; i < batchRows; i++) {
                        ArrayList<Object> row = new ArrayList<Object>();
                        for (int j = 0; j < cols; j++) {
                            if (j == 0) {
                                row.add(String.valueOf((i * 279470273) % 4294967291l));
                            } else {
                                row.add(i + "abcdefghijklmnop" + j);
                            }
                        }
                        batch.add(row);
                    }
                    TupleBatch result = new TupleBatch(start + 1, batch);
                    if (done) {
                        result.setTerminationFlag(true);
                    }
                    return result;
                }

                @Override
                public Object clone() {
                    return null;
                }
            };
            rn.setElements(elems);
            sortNode.addChild(rn);
            sortNode.initialize(context, bm, null);
            rn.initialize(context, bm, null);
            process(sortNode, rows);
            return null;
        }
    };
    runTask(iterations, threads, task);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) OrderBy(org.teiid.query.sql.lang.OrderBy) CommandContext(org.teiid.query.util.CommandContext) SortNode(org.teiid.query.processor.relational.SortNode) ArrayList(java.util.ArrayList) BlockingFakeRelationalNode(org.teiid.query.processor.relational.BlockingFakeRelationalNode) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode) RelationalNode(org.teiid.query.processor.relational.RelationalNode) List(java.util.List) ArrayList(java.util.ArrayList) TupleBatch(org.teiid.common.buffer.TupleBatch)

Aggregations

TupleBatch (org.teiid.common.buffer.TupleBatch)61 Test (org.junit.Test)26 List (java.util.List)23 ArrayList (java.util.ArrayList)22 BlockedException (org.teiid.common.buffer.BlockedException)17 CommandContext (org.teiid.query.util.CommandContext)10 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)9 TeiidProcessingException (org.teiid.core.TeiidProcessingException)8 TeiidComponentException (org.teiid.core.TeiidComponentException)6 BufferManager (org.teiid.common.buffer.BufferManager)4 TupleBuffer (org.teiid.common.buffer.TupleBuffer)4 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)3 TransactionContext (org.teiid.dqp.service.TransactionContext)3 TransactionService (org.teiid.dqp.service.TransactionService)3 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)2 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)2 TeiidException (org.teiid.core.TeiidException)2 QueryProcessor (org.teiid.query.processor.QueryProcessor)2 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)2 CacheHint (org.teiid.query.sql.lang.CacheHint)2