use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestTriggerActions method testInsertRewrite.
/**
* Ensure that we simplify expressions
*/
@Test
public void testInsertRewrite() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table tablea (s string primary key) options (updatable true);\n" + "create view viewa (i integer) options (updatable true) as SELECT cast(s as integer) from tablea;\n" + "create trigger on viewa instead of insert as for each row begin atomic " + "INSERT INTO tablea (tablea.s) VALUES (\"NEW\".i); END;" + "create trigger on viewa instead of update as for each row begin atomic " + "update tablea set s = \"NEW\".i; END;", "x", "y");
String sql = "insert into viewa (i) values (1)";
HardcodedDataManager dm = new HardcodedDataManager();
dm.addData("INSERT INTO tablea (s) VALUES ('1')", Arrays.asList(1));
CommandContext context = createCommandContext();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
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);
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder 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);
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestTriggerActions method testUpdateSetExpression.
@Test
public void testUpdateSetExpression() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table g1 (e1 string, e2 integer) options (updatable true);" + " create view GX options (updatable true) as select '1' as x, 2 as y;" + " create trigger on GX instead of update as for each row begin update g1 set e1 = new.x, e2 = new.y where e2 = old.y; END", "x", "y");
String sql = "update gx set x = x || 'a' where y = 2";
HardcodedDataManager dm = new HardcodedDataManager();
dm.addData("UPDATE g1 SET e1 = '1a', e2 = 2 WHERE e2 = 2", new List[] { Arrays.asList(1) });
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);
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestTriggerActions method testUpdateWithChanging.
@Test
public void testUpdateWithChanging() 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 = case when changing.y then new.y end where e2 = old.y; END");
t.setInsertPlan("");
String sql = "update gx set y = 5";
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 = 5 WHERE e2 = 2", dm.getQueries().get(0));
}
use of org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder in project teiid by teiid.
the class TestTriggerActions method testInsertWithQueryExpressionAndAlias.
@Test
public void testInsertWithQueryExpressionAndAlias() throws Exception {
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign table tablea (TEST_ID integer, TEST_NBR bigdecimal) options (updatable true);\n" + "create foreign table tableb (TEST_ID integer, TEST_NBR bigdecimal);\n" + "create view viewa options (updatable true) as SELECT TEST_ID, TEST_NBR FROM tablea;\n" + "create trigger on viewa instead of insert as for each row begin atomic " + "INSERT INTO tablea (tablea.TEST_ID, tablea.TEST_NBR) VALUES (\"NEW\".TEST_ID, \"NEW\".TEST_NBR); END;", "x", "y");
String sql = "insert into viewa (TEST_ID, TEST_NBR) SELECT TEST_ID AS X, TEST_NBR FROM tableb";
HardcodedDataManager dm = new HardcodedDataManager();
dm.addData("INSERT INTO tablea (TEST_ID, TEST_NBR) VALUES (1, 2.0)", Arrays.asList(1));
dm.addData("SELECT g_0.TEST_ID, g_0.TEST_NBR FROM y.tableb AS g_0", Arrays.asList(1, 2.0));
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);
}
Aggregations