Search in sources :

Example 66 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class Block method addStatement.

public void addStatement(Statement statement, boolean exception) {
    if (statement instanceof AssignmentStatement) {
        AssignmentStatement stmt = (AssignmentStatement) statement;
        Command cmd = stmt.getCommand();
        if (cmd != null) {
            internalAddStatement(new CommandStatement(cmd), exception);
            stmt.setCommand(null);
            stmt.setExpression(null);
            if (stmt.getVariable().getShortName().equalsIgnoreCase(ProcedureReservedWords.ROWCOUNT) && stmt.getVariable().getGroupSymbol() != null && stmt.getVariable().getGroupSymbol().getName().equalsIgnoreCase(ProcedureReservedWords.VARIABLES)) {
                return;
            }
            String fullName = ProcedureReservedWords.VARIABLES + Symbol.SEPARATOR + ProcedureReservedWords.ROWCOUNT;
            stmt.setExpression(new ElementSymbol(fullName));
        }
    }
    internalAddStatement(statement, exception);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Command(org.teiid.query.sql.lang.Command)

Example 67 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestDependentJoins method testLargeSetInDepAccessWithAccessPattern.

@Test
public void testLargeSetInDepAccessWithAccessPattern() {
    // $NON-NLS-1$
    String sql = "SELECT a.e1, b.e1, b.e2 FROM pm4.g1 a INNER JOIN pm1.g1 b ON a.e1=b.e1 AND a.e2 = b.e2";
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { "aa ", "aa ", // $NON-NLS-1$ //$NON-NLS-2$
    0 }), Arrays.asList(new Object[] { "bb   ", "bb   ", // $NON-NLS-1$ //$NON-NLS-2$
    1 }), Arrays.asList(new Object[] { "cc  ", "cc  ", // $NON-NLS-1$ //$NON-NLS-2$
    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);
    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);
    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) Test(org.junit.Test)

Example 68 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestDependentJoins method testLargeSetInDepAccess.

/**
 * SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1
 */
@Test
public void testLargeSetInDepAccess() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1 OPTION MAKEDEP pm6.g1";
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData4(dataManager);
    // 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();
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
    depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
    depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm6", depcaps);
    List[] expected = new List[] { Arrays.asList(new Object[] { // $NON-NLS-1$
    new String("b") }) };
    Command command = TestProcessor.helpParse(sql);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, capFinder);
    // Run query
    TestProcessor.helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 69 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestDependentJoins method testIndependentDupRemoval1.

@Test
public void testIndependentDupRemoval1() {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT pm1.g1.e1, pm1.g1.e2, x.e2 FROM pm1.g1, pm2.g2, /*+ makeind */ (select distinct e1, e2 from pm2.g1) x WHERE x.e1=pm1.g1.e1 AND pm2.g2.e2=x.e2";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "a", 1, 1 }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "b", 1, 1 }) };
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
    caps.setSourceProperty(Capability.MAX_DEPENDENT_PREDICATES, 1);
    QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
    Command command = TestProcessor.helpParse(sql);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, new DefaultCapabilitiesFinder(caps));
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT DISTINCT g_0.e1, g_0.e2 FROM pm2.g1 AS g_0", new List<?>[] { Arrays.asList("b", 1), Arrays.asList("a", 1) });
    dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'b'", new List<?>[] { Arrays.asList("b", 1) });
    dataManager.addData("SELECT g_0.e2 AS c_0 FROM pm2.g2 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList(1), Arrays.asList(2), Arrays.asList(3) });
    dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 WHERE g_0.e1 = 'a'", new List<?>[] { Arrays.asList("a", 1) });
    // Run query
    TestProcessor.helpProcess(plan, dataManager, expected);
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 70 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestDependentJoins method testIndependentDupRemoval.

@Test
public void testIndependentDupRemoval() {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT pm1.g1.e1, pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, pm2.g1 WHERE pm2.g1.e1=pm1.g1.e1 AND pm1.g1.e2<pm2.g1.e2 order by pm1.g1.e1 option makedep pm1.g1";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "a", 0, 3 }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "a", 0, 3 }) };
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
    caps.setSourceProperty(Capability.MAX_DEPENDENT_PREDICATES, 1);
    caps.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
    QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1Cached();
    Command command = TestProcessor.helpParse(sql);
    ProcessorPlan plan = TestProcessor.helpGetPlan(command, fakeMetadata, new DefaultCapabilitiesFinder(caps));
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    TestProcessor.sampleData1(dataManager);
    // Run query
    TestProcessor.helpProcess(plan, dataManager, expected);
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

Command (org.teiid.query.sql.lang.Command)232 Test (org.junit.Test)142 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)90 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)73 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)66 List (java.util.List)64 CommandContext (org.teiid.query.util.CommandContext)38 ArrayList (java.util.ArrayList)37 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)36 BigInteger (java.math.BigInteger)29 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)25 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)21 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)20 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)19 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 LinkedList (java.util.LinkedList)10 QueryParser (org.teiid.query.parser.QueryParser)10 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)10 QueryCommand (org.teiid.query.sql.lang.QueryCommand)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)10