Search in sources :

Example 11 with RelationalNode

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

the class TestProcessor method testComplexJoinExpressionsUsingDependentJoinWithAccessPattern.

/**
 * RLM Case 2077
 * @throws Exception
 */
@Test
public void testComplexJoinExpressionsUsingDependentJoinWithAccessPattern() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) };
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
    // $NON-NLS-1$
    caps.setFunctionSupport("||", true);
    // $NON-NLS-1$
    caps.setFunctionSupport("rtrim", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm4", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm4.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    RealMetadataFactory.setCardinality("pm2.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData2b(dataManager, metadata);
    Command command = helpParse(sql);
    CommandContext context = createCommandContext();
    context.setMetadata(metadata);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
    // Verify a dependent join (not merge join) was used
    assertTrue(plan instanceof RelationalPlan);
    RelationalPlan relationalPlan = (RelationalPlan) plan;
    RelationalNode project = relationalPlan.getRootNode();
    RelationalNode join = project.getChildren()[0];
    // $NON-NLS-1$
    assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode);
    // Run query
    helpProcess(plan, context, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) JoinNode(org.teiid.query.processor.relational.JoinNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) BigInteger(java.math.BigInteger) RelationalNode(org.teiid.query.processor.relational.RelationalNode) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 12 with RelationalNode

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

the class TestProcessor method testComplexJoinExpressionsUsingDependentJoin.

/**
 * RLM Case 2077
 * @throws Exception
 */
@Test
public void testComplexJoinExpressionsUsingDependentJoin() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm1.g1 a, pm2.g1 b where rtrim(a.e1)=(b.e1 || b.e1)";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "bb   ", "b", new Integer(0) }) };
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
    // $NON-NLS-1$
    caps.setFunctionSupport("||", true);
    // $NON-NLS-1$
    caps.setFunctionSupport("rtrim", true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm2", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1();
    RealMetadataFactory.setCardinality("pm1.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY + 1000, metadata);
    RealMetadataFactory.setCardinality("pm2.g1", RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY - 1, metadata);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData2b(dataManager, metadata);
    Command command = helpParse(sql);
    CommandContext context = createCommandContext();
    context.setMetadata(metadata);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder, context);
    // Verify a dependent join (not merge join) was used
    assertTrue(plan instanceof RelationalPlan);
    RelationalPlan relationalPlan = (RelationalPlan) plan;
    RelationalNode project = relationalPlan.getRootNode();
    RelationalNode join = project.getChildren()[0];
    // $NON-NLS-1$
    assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode);
    // Run query
    helpProcess(plan, context, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) JoinNode(org.teiid.query.processor.relational.JoinNode) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) BigInteger(java.math.BigInteger) RelationalNode(org.teiid.query.processor.relational.RelationalNode) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 13 with RelationalNode

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

the class TestDependentJoins method helpTestDepAccessCausingSortNodeInsert.

public void helpTestDepAccessCausingSortNodeInsert(boolean accessNodeHandlesAliases) {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e2=b.e2 AND a.e1 = b.e1 OPTION MAKEDEP a";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "aa ", "aa ", 0 }), // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "bb   ", "bb   ", 1 }), // $NON-NLS-1$ //$NON-NLS-2$
    Arrays.asList(new Object[] { "cc  ", "cc  ", 2 }) };
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
    depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
    depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    if (accessNodeHandlesAliases) {
        depcaps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    }
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm4", depcaps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // Slightly modify metadata to set max set size to just a few rows - this
    // will allow us to test the dependent overflow case
    QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
    Command command = TestProcessor.helpParse(sql);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
    // Verify a dependent join (not merge join) was used
    assertTrue(plan instanceof RelationalPlan);
    RelationalPlan relationalPlan = (RelationalPlan) plan;
    RelationalNode project = relationalPlan.getRootNode();
    RelationalNode join = project.getChildren()[0];
    // $NON-NLS-1$
    assertTrue("Expected instance of JoinNode (for dep join) but got " + join.getClass(), join instanceof JoinNode);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData2b(dataManager, fakeMetadata);
    // Run query
    TestProcessor.helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) RelationalNode(org.teiid.query.processor.relational.RelationalNode) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) JoinNode(org.teiid.query.processor.relational.JoinNode) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan)

Example 14 with RelationalNode

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

RelationalNode (org.teiid.query.processor.relational.RelationalNode)14 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)12 Test (org.junit.Test)6 JoinNode (org.teiid.query.processor.relational.JoinNode)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)5 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)5 Command (org.teiid.query.sql.lang.Command)5 AccessNode (org.teiid.query.processor.relational.AccessNode)4 List (java.util.List)3 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)3 CommandContext (org.teiid.query.util.CommandContext)3 BigInteger (java.math.BigInteger)2 TupleBatch (org.teiid.common.buffer.TupleBatch)2 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)2 SubqueryAwareRelationalNode (org.teiid.query.processor.relational.SubqueryAwareRelationalNode)2 LanguageObject (org.teiid.query.sql.LanguageObject)2 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)2 ArrayList (java.util.ArrayList)1 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)1