use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestAsynch method oneTimeSetup.
@BeforeClass
public static void oneTimeSetup() throws Exception {
server = new FakeServer(true);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("v");
mmd.setModelType(Type.PHYSICAL);
mmd.setSchemaSourceType("ddl");
mmd.addSourceMapping("z", "z", null);
mmd.setSchemaText("create view test (col integer) as select 1; create foreign table someTable (col integer);");
ef = new HardCodedExecutionFactory() {
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
partIds.add(executionContext.getPartIdentifier());
return super.createResultSetExecution(command, executionContext, metadata, connection);
}
};
server.addTranslator("z", ef);
server.deployVDB("x", mmd);
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method testInternalWriteThroughMativew.
@Test
public void testInternalWriteThroughMativew() throws Exception {
HardCodedExecutionFactory hcef = setupData(true, server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true," + "UPDATABLE true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:MATVIEW_WRITE_THROUGH\" true, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Connection c = server.createConnection("jdbc:teiid:comp");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(3, rs.getInt(1));
hcef.addUpdate("INSERT INTO physicalTbl (col, col1) VALUES (4, 'continent')", new int[] { 1 });
s.execute("insert into v1 (col, col1) values (4, 'continent')");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(4, rs.getInt(1));
// check that not specifying the pk doesn't update the mat view
// TODO: this may be addressed in some cases eventually
hcef.addUpdate("INSERT INTO physicalTbl (col1) VALUES ('continent')", new int[] { 1 });
s.execute("insert into v1 (col1) values ('continent')");
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(4, rs.getInt(1));
hcef.addUpdate("DELETE FROM physicalTbl WHERE physicalTbl.col1 = 'continent'", new int[] { 1 });
s.execute("delete from v1 where v1.col1 = 'continent'");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(3, rs.getInt(1));
hcef.addUpdate("UPDATE physicalTbl SET col1 = 'town' WHERE physicalTbl.col1 = 'city'", new int[] { 1 });
s.execute("update v1 set col1 = 'town' where col1 = 'city'");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select col, col1 from v1 where col = 1");
rs.next();
assertEquals("town", rs.getString(2));
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method withMergeDelete.
private void withMergeDelete(boolean useUpdateScript) throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
assertTest(useUpdateScript, hcef);
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method testLazyUpdate.
@Test
public void testLazyUpdate() throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_MAX_STALENESS_PCT\" '10', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Thread.sleep(1000);
// check if materilization is loaded
Connection c = h2DataSource.getConnection();
ResultSet rs = c.createStatement().executeQuery("SELECT LoadState, StaleCount FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("LOADED", rs.getString(1));
assertEquals(0, rs.getInt(2));
// verify with querying the database.
conn = server.createConnection("jdbc:teiid:comp");
Statement s = conn.createStatement();
rs = s.executeQuery("select * from view1.v1 order by col");
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("town", rs.getString(2));
// send a row update
EventDistributor ed = server.getEventDistributor();
ResultsFuture<?> f = ed.dataModification("comp", "1", "source", "physicalTbl", new Object[] { 1, "town" }, new Object[] { 1, "town-modified" }, new String[] { "col1", "col2" });
f.get();
f = ed.dataModification("comp", "1", "source", "physicalTbl", new Object[] { 1, "town" }, new Object[] { 1, "town-modified" }, new String[] { "col1", "col2" });
f.get();
// check the stale count incremented
rs = c.createStatement().executeQuery("SELECT LoadState, StaleCount FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("NEEDS_LOADING", rs.getString(1));
assertEquals(1, rs.getInt(2));
// now reload the view, this should reset the stalecount. If you can wait one minute this occurs automatically
conn.createStatement().execute("exec SYSADMIN.loadMatView(schemaName=>'view1', viewName=>'v1', invalidate=>false)");
// check the stale count to zero
rs = c.createStatement().executeQuery("SELECT LoadState, StaleCount FROM Status WHERE VDBName = 'comp'");
rs.next();
assertEquals("LOADED", rs.getString(1));
assertEquals(0, rs.getInt(2));
String ddl = server.getAdmin().getSchema("comp", "1", "source", null, null);
assertFalse(ddl.contains("AFTER INSERT"));
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestExternalMatViews method test.
@Test
public void test() throws Exception {
HardCodedExecutionFactory hcef = setupData(server);
ModelMetaData sourceModel = setupSourceModel();
ModelMetaData matViewModel = setupMatViewModel();
ModelMetaData viewModel = new ModelMetaData();
viewModel.setName("view1");
viewModel.setModelType(Type.VIRTUAL);
viewModel.addSourceMetadata("DDL", "CREATE VIEW v1 (col integer primary key, col1 string) " + "OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'matview.MAT_V2', " + "\"teiid_rel:MATVIEW_TTL\" 3000, " + "\"teiid_rel:ALLOW_MATVIEW_MANAGEMENT\" true, " + "\"teiid_rel:MATVIEW_STATUS_TABLE\" 'matview.STATUS', " + "\"teiid_rel:MATVIEW_LOADNUMBER_COLUMN\" 'loadnum') " + "AS select col, col1 from source.physicalTbl");
server.deployVDB("comp", sourceModel, viewModel, matViewModel);
Connection admin = server.createConnection("jdbc:teiid:comp");
execute(admin, "select * from SYSADMIN.Usage where Name = 'mat_v1'");
admin.close();
}
Aggregations