Search in sources :

Example 36 with Command

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

the class TestProcessor method testCase4531.

@Test
public void testCase4531() {
    // $NON-NLS-1$
    String sql = "select intkey, intnum from (select intnum as intkey, 1 as intnum from bqt1.smalla union all select intkey, intnum from bqt1.smalla union all select intkey, intnum from bqt2.smalla) x";
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_UNION, true);
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT2", caps);
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.exampleBQTCached(), capFinder);
    // Run query
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1) }) };
    // Construct data manager with data
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "SELECT g_0.IntKey, g_0.IntNum FROM BQT2.SmallA AS g_0", new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) }) });
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "SELECT g_1.IntNum AS c_0, 1 AS c_1 FROM BQT1.SmallA AS g_1 UNION ALL SELECT g_0.IntKey AS c_0, g_0.IntNum AS c_1 FROM BQT1.SmallA AS g_0", new List[] { Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1) }) });
    helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BigInteger(java.math.BigInteger) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) Test(org.junit.Test)

Example 37 with Command

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

the class TestProcessor method testMultipleAliasInUnionAll.

@Test
public void testMultipleAliasInUnionAll() {
    String sql = "SELECT enterprise_id FROM ( " + "SELECT * FROM ( " + "    SELECT id, id AS display_id, 103 AS enterprise_id FROM (" + "        SELECT 'x' as id, e1 FROM pm1.g1) AS nexted103) as table103Source " + "UNION ALL " + "SELECT  'x', 'x' AS display_id, 101 AS enterprise_id FROM (" + "    SELECT 'x', e1 FROM pm1.g1) AS nested101 " + "UNION ALL " + "SELECT  'x', 'x' AS display_id, 100 AS enterprise_id FROM (" + "    SELECT 'x', e1 FROM pm1.g1) AS nested100) as tableFrom1stSelect " + "WHERE enterprise_id = 100";
    // Create expected results - would expect these to be:
    List[] expected = new List[] { Arrays.asList(100) };
    // Construct data manager with data
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT 100 FROM pm1.g1 AS g_0", new List[] { Arrays.asList(100) });
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.example1Cached(), TestOptimizer.getGenericFinder(false));
    // Run query
    helpProcess(plan, dataManager, expected);
}
Also used : Command(org.teiid.query.sql.lang.Command) Test(org.junit.Test)

Example 38 with Command

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

the class TestProcessor method testPushdownLiteralInSelectUnderAggregate.

@Test
public void testPushdownLiteralInSelectUnderAggregate() {
    // $NON-NLS-1$
    String sql = "SELECT COUNT(*) FROM (SELECT '' AS y, a.IntKey FROM BQT1.SmallA a union all select '', b.intkey from bqt1.smallb b) AS x";
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(30) }) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataBQT2(dataManager);
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    caps.setCapabilitySupport(Capability.QUERY_UNION, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
    caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    // Run query
    helpProcess(plan, dataManager, expected);
}
Also used : BigInteger(java.math.BigInteger) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 39 with Command

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

the class TestProcessor method testDefect15355d.

@Test
public void testDefect15355d() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT StringKey, BigIntegerValue FROM VQT.Defect15355a WHERE StringKey = '0'";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$  //$NON-NLS-2$
    Arrays.asList(new Object[] { "0", new BigInteger("0") }) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataBQT2a(dataManager);
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT2", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT3", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    // Run query
    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) BigInteger(java.math.BigInteger) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 40 with Command

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

the class TestProcessor method testDefect15355c.

@Test
public void testDefect15355c() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT StringKey, BigIntegerValue FROM VQT.Defect15355 WHERE StringKey = '0'";
    // Create expected results
    List[] expected = new List[] { // $NON-NLS-1$  //$NON-NLS-2$
    Arrays.asList(new Object[] { "0", new BigInteger("0") }) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleDataBQT2a(dataManager);
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT2", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT3", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    // Run query
    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) BigInteger(java.math.BigInteger) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) 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