Search in sources :

Example 1 with SortNode

use of org.teiid.query.processor.relational.SortNode in project teiid by teiid.

the class TestRuleMergeVirtual method testSortAliasWithSameName.

@Test
public void testSortAliasWithSameName() throws Exception {
    // $NON-NLS-1$
    String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x order by e1";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    RelationalPlan plan = (RelationalPlan) TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, capFinder, // $NON-NLS-1$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    SortNode node = (SortNode) plan.getRootNode();
    // $NON-NLS-1$
    assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol()));
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) SortNode(org.teiid.query.processor.relational.SortNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 2 with SortNode

use of org.teiid.query.processor.relational.SortNode in project teiid by teiid.

the class TestRuleMergeVirtual method testSortAliasWithSameNameUnion.

@Test
public void testSortAliasWithSameNameUnion() throws Exception {
    // $NON-NLS-1$
    String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x union all select e1 from pm1.g2 order by e1";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    RelationalPlan plan = (RelationalPlan) TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0", "SELECT g_0.e1 FROM pm1.g2 AS g_0" }, capFinder, // $NON-NLS-1$
    TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
    SortNode node = (SortNode) plan.getRootNode();
    // $NON-NLS-1$
    assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol()));
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) SortNode(org.teiid.query.processor.relational.SortNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Test(org.junit.Test)

Example 3 with SortNode

use of org.teiid.query.processor.relational.SortNode 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)

Example 4 with SortNode

use of org.teiid.query.processor.relational.SortNode in project teiid by teiid.

the class TestEnginePerformance method helpTestSort.

public void helpTestSort(Mode mode, int expectedRowCount, List<? extends Expression> sortElements, List<?>[] data, List<? extends Expression> elems, BufferManager bufferManager) throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$ //$NON-NLS-2$
    CommandContext context = new CommandContext("pid", "test", null, null, 1);
    BlockingFakeRelationalNode dataNode = new BlockingFakeRelationalNode(0, data);
    dataNode.setReturnPeriod(3);
    dataNode.setElements(elems);
    dataNode.initialize(context, bufferManager, null);
    SortNode sortNode = new SortNode(1);
    sortNode.setSortElements(new OrderBy(sortElements).getOrderByItems());
    sortNode.setMode(mode);
    sortNode.setElements(dataNode.getElements());
    sortNode.addChild(dataNode);
    sortNode.initialize(context, bufferManager, null);
    process(sortNode, expectedRowCount);
}
Also used : OrderBy(org.teiid.query.sql.lang.OrderBy) BlockingFakeRelationalNode(org.teiid.query.processor.relational.BlockingFakeRelationalNode) CommandContext(org.teiid.query.util.CommandContext) SortNode(org.teiid.query.processor.relational.SortNode)

Aggregations

SortNode (org.teiid.query.processor.relational.SortNode)4 Test (org.junit.Test)2 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)2 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)2 BlockingFakeRelationalNode (org.teiid.query.processor.relational.BlockingFakeRelationalNode)2 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)2 OrderBy (org.teiid.query.sql.lang.OrderBy)2 CommandContext (org.teiid.query.util.CommandContext)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TupleBatch (org.teiid.common.buffer.TupleBatch)1 FakeRelationalNode (org.teiid.query.processor.relational.FakeRelationalNode)1 RelationalNode (org.teiid.query.processor.relational.RelationalNode)1 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)1