Search in sources :

Example 86 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestTriggerActions method testInsert.

@Test
public void testInsert() throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView("select 1 as x, 2 as y", metadata, GX);
    Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
    t.setDeletePlan("");
    t.setUpdatePlan("");
    t.setInsertPlan("FOR EACH ROW BEGIN insert into pm1.g1 (e1) values (new.x); END");
    String sql = "insert into gx (x, y) values (1, 2)";
    FakeDataManager dm = new FakeDataManager();
    FakeDataStore.addTable("pm1.g1", dm, metadata);
    CommandContext context = createCommandContext();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
    List<?>[] expected = new List[] { Arrays.asList(1) };
    helpProcess(plan, context, dm, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 87 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestTriggerActions method testDynamicRecursion.

@Test
public void testDynamicRecursion() throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView("select 'a' as x, 2 as y", metadata, GX);
    Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
    t.setDeletePlan("FOR EACH ROW BEGIN ATOMIC insert into gx (x, y) values (old.x, old.y); END");
    t.setUpdatePlan("");
    t.setInsertPlan("FOR EACH ROW BEGIN execute immediate 'delete from gx where gx.x = new.x'; END");
    String sql = "insert into gx (x, y) select e1, e2 from pm1.g1";
    FakeDataManager dm = new FakeDataManager();
    FakeDataStore.addTable("pm1.g1", dm, metadata);
    CommandContext context = createCommandContext();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
    try {
        helpProcess(plan, context, dm, null);
        fail();
    } catch (QueryProcessingException e) {
        assertEquals("TEIID30168 Couldn't execute the dynamic SQL command \"EXECUTE IMMEDIATE 'delete from gx where gx.x = new.x'\" with the SQL statement \"delete from gx where gx.x = new.x\" due to: TEIID30347 There is a recursive invocation of group 'I gx'. Please correct the SQL.", e.getMessage());
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) QueryProcessingException(org.teiid.api.exception.query.QueryProcessingException) Test(org.junit.Test)

Example 88 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestTriggerActions method testDynamic.

@Test
public void testDynamic() throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView("select '1' as x, 2 as y", metadata, GX);
    Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
    t.setDeletePlan("FOR EACH ROW BEGIN ATOMIC END");
    t.setUpdatePlan("");
    t.setInsertPlan("FOR EACH ROW BEGIN execute immediate 'delete from gx where gx.x = new.x'; END");
    String sql = "insert into gx (x, y) select e1, e2 from pm1.g1";
    FakeDataManager dm = new FakeDataManager();
    FakeDataStore.addTable("pm1.g1", dm, metadata);
    CommandContext context = createCommandContext();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
    List<?>[] expected = new List[] { Arrays.asList(6) };
    helpProcess(plan, context, dm, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 89 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestTriggerActions method testUpdateWithNonConstant.

@Test
public void testUpdateWithNonConstant() throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView("select 1 as x, 2 as y", metadata, GX);
    Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
    t.setDeletePlan("");
    t.setUpdatePlan("FOR EACH ROW BEGIN update pm1.g1 set e2 = new.y where e2 = old.y; END");
    t.setInsertPlan("");
    String sql = "update gx set y = x";
    FakeDataManager dm = new FakeDataManager();
    FakeDataStore.addTable("pm1.g1", dm, metadata);
    CommandContext context = createCommandContext();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
    List<?>[] expected = new List[] { Arrays.asList(1) };
    helpProcess(plan, context, dm, expected);
    assertEquals("UPDATE pm1.g1 SET e2 = 1 WHERE e2 = 2", dm.getQueries().get(0));
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 90 with Table

use of org.teiid.metadata.Table in project teiid by teiid.

the class TestTriggerActions method testInsertWithDefault.

@Test
public void testInsertWithDefault() throws Exception {
    TransformationMetadata metadata = TestUpdateValidator.example1();
    TestUpdateValidator.createView("select 1 as x, 2 as y", metadata, GX);
    Table t = metadata.getMetadataStore().getSchemas().get(VM1).getTables().get(GX);
    t.setDeletePlan("");
    t.setUpdatePlan("");
    t.setInsertPlan("FOR EACH ROW BEGIN insert into pm1.g1 (e1) values (new.x); END");
    String sql = "insert into gx (x) values (1)";
    FakeDataManager dm = new FakeDataManager();
    FakeDataStore.addTable("pm1.g1", dm, metadata);
    CommandContext context = createCommandContext();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    ProcessorPlan plan = TestProcessor.helpGetPlan(TestResolver.helpResolve(sql, metadata), metadata, new DefaultCapabilitiesFinder(caps), context);
    List<?>[] expected = new List[] { Arrays.asList(1) };
    helpProcess(plan, context, dm, expected);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) List(java.util.List) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Aggregations

Table (org.teiid.metadata.Table)239 Test (org.junit.Test)82 Column (org.teiid.metadata.Column)72 MetadataFactory (org.teiid.metadata.MetadataFactory)59 Properties (java.util.Properties)45 MetadataStore (org.teiid.metadata.MetadataStore)37 Schema (org.teiid.metadata.Schema)35 TranslatorException (org.teiid.translator.TranslatorException)30 ArrayList (java.util.ArrayList)27 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)27 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)23 List (java.util.List)22 ForeignKey (org.teiid.metadata.ForeignKey)22 Connection (java.sql.Connection)15 QueryNode (org.teiid.query.mapping.relational.QueryNode)15 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)15 KeyRecord (org.teiid.metadata.KeyRecord)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)13 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)13