Search in sources :

Example 76 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestProcessor method testUpdateCompensation.

@Test
public void testUpdateCompensation() {
    // $NON-NLS-1$
    String sql = "update pm1.g1 set e4 = null where e1 = 'a' and exists (select 1 from pm1.g2 where e2 = pm1.g1.e2)";
    List[] expected = new List[] { Arrays.asList(3) };
    FakeDataManager dataManager = new FakeDataManager();
    sampleData1(dataManager);
    BasicSourceCapabilities caps = getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, false);
    ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example4(), new DefaultCapabilitiesFinder(caps));
    helpProcess(plan, dataManager, expected);
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 77 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestProcessor method testNonDeterministicPushdown.

@Test
public void testNonDeterministicPushdown() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "SELECT RAND(), lookup('pm1.g1', 'e1', 'e2', 1) FROM pm1.g1 limit 2";
    List[] expected = new List[] { Arrays.asList(new Double(0.1), "a"), Arrays.asList(new Double(0.2), "a") };
    // Construct data manager with data
    HardcodedDataManager hdm = new HardcodedDataManager();
    hdm.addData("SELECT RAND() FROM pm1.g1", new List[] { Arrays.asList(.1), Arrays.asList(.2) });
    hdm.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List<?>[] { Arrays.asList(1, "a") });
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    bsc.setFunctionSupport(SourceSystemFunctions.RAND, true);
    // Plan query
    CommandContext cc = createCommandContext();
    ProcessorPlan plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
    helpProcess(plan, cc, hdm, expected);
    bsc.setFunctionSupport(SourceSystemFunctions.RAND, false);
    plan = helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(bsc), cc);
    hdm = new HardcodedDataManager();
    hdm.addData("SELECT 'a' FROM pm1.g1", new List[] { Arrays.asList("a"), Arrays.asList("a") });
    hdm.addData("SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1", new List<?>[] { Arrays.asList(1, "a") });
    Random r = new Random(0);
    r.nextDouble();
    expected = new List[] { Arrays.asList(r.nextDouble(), "a"), Arrays.asList(r.nextDouble(), "a") };
    helpProcess(plan, cc, hdm, expected);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 78 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestProcessor method testUpdateNonDeterministic.

@Test
public void testUpdateNonDeterministic() {
    String sql = "update pm1.g2 set e1 = (with u (id) as (select uuid()) select id from u) where e1 = 'xxxx'";
    FakeDataManager dataManager = new FakeDataManager();
    sampleData1(dataManager);
    BasicSourceCapabilities caps = getTypicalCapabilities();
    ProcessorPlan plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps));
    helpProcess(plan, dataManager, new List[] { Arrays.asList(0) });
    // same as above
    sql = "update pm1.g2 set e1 = (select uuid()) where e1 = 'xxxx'";
    plan = helpGetPlan(sql, RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps));
    helpProcess(plan, dataManager, new List[] { Arrays.asList(0) });
    sql = "update pm1.g2 set e1 = uuid() where e1 = 'xxxx'";
    try {
        helpGetPlan(helpParse(sql), RealMetadataFactory.example1Cached(), new DefaultCapabilitiesFinder(caps), createCommandContext());
        fail();
    } catch (TeiidException e) {
    // no primary key
    }
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidException(org.teiid.core.TeiidException) Test(org.junit.Test)

Example 79 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestProcessor method testCase6193_2.

/**
 * Here a merge join will be used since there is at least one equi join predicate.
 */
@Test
public void testCase6193_2() throws Exception {
    // Create query
    // $NON-NLS-1$
    String sql = "select a.e2, b.e2 from pm1.g1 a LEFT OUTER JOIN pm1.g2 b on a.e4=b.e4 and (a.e2+b.e2)=4 order by a.e2";
    // Create expected results
    List[] expected = new List[] { Arrays.asList(new Object[] { new Integer(0), null }), Arrays.asList(new Object[] { new Integer(0), null }), Arrays.asList(new Object[] { new Integer(1), null }), Arrays.asList(new Object[] { new Integer(1), null }), Arrays.asList(new Object[] { new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(3), null }) };
    // Construct data manager with data
    FakeDataManager dataManager = new FakeDataManager();
    sampleData1(dataManager);
    // Plan query
    ProcessorPlan plan = TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] { "SELECT a.e4, a.e2 FROM pm1.g1 AS a", "SELECT b.e4, b.e2 FROM pm1.g2 AS b" }, new DefaultCapabilitiesFinder(), // $NON-NLS-1$ //$NON-NLS-2$
    ComparisonMode.CORRECTED_COMMAND_STRING);
    TestOptimizer.checkNodeTypes(plan, new int[] { // Access
    2, // DependentAccess
    0, // DependentSelect
    0, // DependentProject
    0, // DupRemove
    0, // Grouping
    0, // NestedLoopJoinStrategy
    0, // MergeJoinStrategy
    1, // Null
    0, // PlanExecution
    0, // Project
    1, // Select
    0, // Sort
    1, // UnionAll
    0 });
    // Run query
    helpProcess(plan, dataManager, expected);
}
Also used : BigInteger(java.math.BigInteger) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 80 with DefaultCapabilitiesFinder

use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.

the class TestProcessor method testMixedAnsiLateralJoinsWithConstantProjection.

@Test
public void testMixedAnsiLateralJoinsWithConstantProjection() throws Exception {
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("CREATE VIRTUAL PROCEDURE pr0(arg1 string) returns (res1 string) AS\n" + "    BEGIN\n" + "        SELECT '2017-01-01';\n" + "    END;" + "create foreign table test_t1(col_t1 varchar) options (cardinality 1)", "x", "y");
    String sql = "SELECT d.*,x.*,xxx.*,dl.*\n" + "    FROM (SELECT 'League' AS type, 1 AS arg0) xxx, test_t1 dl, table(CALL pr0(arg0)) x\n" + "    JOIN test_t1 d ON d.col_t1 = 'str_val'";
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(Capability.QUERY_FROM_JOIN_LATERAL, true);
    ProcessorPlan plan = TestProcessor.helpGetPlan(sql, metadata, new DefaultCapabilitiesFinder(caps));
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT g_0.col_t1 FROM y.test_t1 AS g_0 WHERE g_0.col_t1 = 'str_val'", Arrays.asList("str_val"));
    dataManager.addData("SELECT g_0.col_t1 FROM y.test_t1 AS g_0", Arrays.asList("str_val"));
    TestProcessor.helpProcess(plan, dataManager, new List<?>[] { Arrays.asList("str_val", "2017-01-01", "League", 1, "str_val") });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)361 Test (org.junit.Test)344 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)277 List (java.util.List)121 CommandContext (org.teiid.query.util.CommandContext)95 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)89 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)87 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)42 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)41 Command (org.teiid.query.sql.lang.Command)23 CapabilitiesFinder (org.teiid.query.optimizer.capabilities.CapabilitiesFinder)17 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)15 ArrayList (java.util.ArrayList)13 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)13 PermissionMetaData (org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData)13 Table (org.teiid.metadata.Table)12 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)7 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)7 TeiidComponentException (org.teiid.core.TeiidComponentException)6 TeiidProcessingException (org.teiid.core.TeiidProcessingException)6