Search in sources :

Example 31 with Command

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

the class TestProcessor method testDefect13920.

@Test
public void testDefect13920() throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, false);
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_ORDERED, false);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    // $NON-NLS-1$
    Command command = helpParse("SELECT e5, e2, e3, e4 FROM vm1.g1c WHERE e5 >= {ts'2004-08-01 00:00:00.0'}");
    ProcessorPlan plan = helpGetPlan(command, RealMetadataFactory.example1Cached(), capFinder);
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    dataManager.registerTuples(RealMetadataFactory.example1Cached(), "pm1.g1", new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "Jan 01 2004 12:00:00", new Integer(0), Boolean.FALSE, new Double(2.0) }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Dec 31 2004 12:00:00", new Integer(1), Boolean.TRUE, null }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "Aug 01 2004 12:00:00", new Integer(2), Boolean.FALSE, new Double(0.0) }) });
    Calendar cal = Calendar.getInstance();
    cal.set(2004, Calendar.DECEMBER, 31, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Timestamp t1 = new Timestamp(cal.getTime().getTime());
    cal.clear();
    cal.set(2004, Calendar.AUGUST, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Timestamp t2 = new Timestamp(cal.getTime().getTime());
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { t1, new Integer(1), Boolean.TRUE, null }), Arrays.asList(new Object[] { t2, new Integer(2), Boolean.FALSE, new Double(0.0) }) };
    // Run query
    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) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 32 with Command

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

the class TestProcessor method testInnerCorrelatedReference.

/**
 * The inner most A.e1 was mistakenly getting transformed into pm1.g3.e1
 */
@Test
public void testInnerCorrelatedReference() throws Exception {
    // $NON-NLS-1$
    String sql = "SELECT DISTINCT A.e1 FROM pm1.g3 AS A WHERE (A.e1 IN (SELECT A.e1 FROM pm1.g3))";
    // Create expected results
    List[] expected = new List[] {};
    // Construct data manager with data
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData("SELECT DISTINCT g_0.e1 FROM pm1.g3 AS g_0 WHERE g_0.e1 IN (SELECT g_0.e1 FROM pm1.g3 AS g_1)", expected);
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    caps.setCapabilitySupport(Capability.QUERY_SUBQUERIES_CORRELATED, true);
    caps.setCapabilitySupport(Capability.CRITERIA_IN_SUBQUERY, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    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) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 33 with Command

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

the class TestProcessor method testSourceDoesntSupportGroupAlias.

@Test
public void testSourceDoesntSupportGroupAlias() {
    // $NON-NLS-1$
    String sql = "SELECT a.IntKey, b.IntKey FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.IntKey = 5 AND A.IntKey = b.IntKey";
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
    // $NON-NLS-1$
    assertEquals("Expected one query to get pushed down", 1, atomicQueries.size());
    String atomicSql = atomicQueries.iterator().next().toString();
    // $NON-NLS-1$
    String expectedSql = "SELECT BQT1.SmallA.IntKey, BQT1.SmallB.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) AND (BQT1.SmallA.IntKey = 5)";
    assertEquals(expectedSql, atomicSql);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(5), new Integer(5) }) };
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData(expectedSql, expected);
    helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BigInteger(java.math.BigInteger) ColumnSet(org.teiid.metadata.ColumnSet) 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 34 with Command

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

the class TestProcessor method testProjectionErrorOverUnionWithConvert.

@Test
public void testProjectionErrorOverUnionWithConvert() {
    // Create query
    QueryMetadataInterface metadata = createProjectErrorMetadata();
    // $NON-NLS-1$
    String sql = "SELECT COUNT(*) FROM v1.u1";
    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("p1", caps);
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    // Run query
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(2) }) };
    // Construct data manager with data
    HardcodedDataManager dataManager = new HardcodedDataManager();
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "SELECT 1 AS c_0 FROM p1.t AS g_1 UNION ALL SELECT 1 AS c_0 FROM p1.t AS g_0", new List[] { Arrays.asList(1), Arrays.asList(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) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 35 with Command

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

the class TestProcessor method testSourceDoesntSupportGroupAliasInVirtual.

/**
 * Same as testSourceDoesntSupportGroupAlias, but query is in an inline view and only
 * the first column is selected.
 *
 * @since 4.2
 */
@Test
public void testSourceDoesntSupportGroupAliasInVirtual() {
    // $NON-NLS-1$
    String sql = "SELECT x FROM (SELECT a.IntKey as x, b.IntKey as y FROM BQT1.SmallA a, BQT1.SmallB b WHERE a.IntKey = 5 AND A.IntKey = b.IntKey) AS z, BQT2.SmallA WHERE y = IntKey";
    // Plan query
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    caps.setCapabilitySupport(Capability.CRITERIA_COMPARE_EQ, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, true);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT1", caps);
    // $NON-NLS-1$
    capFinder.addCapabilities("BQT2", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    Set atomicQueries = TestOptimizer.getAtomicQueries(plan);
    // $NON-NLS-1$
    assertEquals("Expected 2 queries to get pushed down", 2, atomicQueries.size());
    // $NON-NLS-1$
    String expectedSql = "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallA, BQT1.SmallB WHERE (BQT1.SmallA.IntKey = BQT1.SmallB.IntKey) AND (BQT1.SmallA.IntKey = 5) AND (BQT1.SmallB.IntKey = 5)";
    // $NON-NLS-1$
    String expectedSql2 = "SELECT BQT2.SmallA.IntKey FROM BQT2.SmallA WHERE BQT2.SmallA.IntKey = 5";
    Set expectedQueries = new HashSet();
    expectedQueries.add(expectedSql);
    expectedQueries.add(expectedSql2);
    assertEquals(expectedQueries, atomicQueries);
    List[] input1 = new List[] { Arrays.asList(new Object[] { new Integer(5), new Integer(5) }) };
    List[] input2 = new List[] { Arrays.asList(new Object[] { new Integer(5) }) };
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData(expectedSql, input1);
    dataManager.addData(expectedSql2, input2);
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(5) }) };
    helpProcess(plan, dataManager, expected);
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) BigInteger(java.math.BigInteger) ColumnSet(org.teiid.metadata.ColumnSet) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Command(org.teiid.query.sql.lang.Command) 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