use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testMatViewWithImportedVDB.
@Test
public void testMatViewWithImportedVDB() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("phy");
mmd.setSchemaSourceType("DDL");
mmd.setSchemaText("CREATE FOREIGN TABLE t1 ( col1 string, col2 integer )");
mmd.addSourceMapping("phy", "loopback", null);
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("phy_mv");
mmd1.setSchemaSourceType("DDL");
mmd1.setSchemaText("CREATE FOREIGN TABLE t1_mv ( col1 string, col2 integer )" + " create foreign table status (VDBNAME STRING, VDBVERSION STRING, " + " SCHEMANAME STRING, NAME STRING, TARGETSCHEMANAME STRING, TARGETNAME STRING, " + " VALID BOOLEAN, LOADSTATE STRING, CARDINALITY LONG, UPDATED TIMESTAMP, LOADNUMBER LONG, NODENAME STRING, STALECOUNT LONG)");
mmd1.addSourceMapping("phy_mv", "loopback", null);
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("view1");
mmd2.setModelType(Type.VIRTUAL);
mmd2.setSchemaSourceType("DDL");
mmd2.setSchemaText("CREATE VIEW v1 ( col1 string, col2 integer ) OPTIONS (MATERIALIZED true, " + "MATERIALIZED_TABLE 'phy_mv.t1_mv', \"teiid_rel:MATVIEW_STATUS_TABLE\" 'phy_mv.status', \"teiid_rel:MATVIEW_LOAD_SCRIPT\" 'select 1') AS select t1.col1, t1.col2 FROM t1");
server.addTranslator(LoopbackExecutionFactory.class);
server.deployVDB("base", mmd, mmd1, mmd2);
VDBMetaData vdbMetaData = new VDBMetaData();
vdbMetaData.setXmlDeployment(true);
VDBImportMetadata importVDB = new VDBImportMetadata();
importVDB.setName("base");
importVDB.setVersion("1");
vdbMetaData.getVDBImports().add(importVDB);
vdbMetaData.setName("importing");
server.deployVDB(vdbMetaData);
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testMatViewProceduresWithSameName.
@Test
public void testMatViewProceduresWithSameName() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.VIRTUAL);
mmd.addSourceMetadata("DDL", "create view T as select 1");
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("y");
mmd1.setModelType(Type.VIRTUAL);
mmd1.addSourceMetadata("DDL", "create view T as select 1");
server.deployVDB("test", mmd, mmd1);
Connection c = server.getDriver().connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
try {
s.execute("call sysadmin.matviewstatus('x', 'T')");
} catch (TeiidSQLException e) {
e.getTeiidCode().equals("TEIID30167");
}
try {
s.execute("call sysadmin.loadmatview('x', 'T')");
} catch (TeiidSQLException e) {
e.getTeiidCode().equals("TEIID30167");
}
try {
s.execute("call sysadmin.updateMatView('x', 'T')");
} catch (TeiidSQLException e) {
e.getTeiidCode().equals("TEIID30167");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testCompositeupdateMatViewInternal.
@Test
public void testCompositeupdateMatViewInternal() throws Exception {
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("view1");
mmd2.setModelType(Type.VIRTUAL);
mmd2.addSourceMetadata("DDL", "CREATE VIEW v1 ( col integer, col1 string, col2 double, primary key (col, col1) ) OPTIONS (MATERIALIZED true) AS /*+ cache(updatable) */ select 1, current_database(), rand()");
server.deployVDB("comp", mmd2);
Connection c = server.getDriver().connect("jdbc:teiid:comp", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from v1");
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("comp", rs.getString(2));
double previous = rs.getDouble(3);
rs = s.executeQuery("select * from (call sysadmin.updateMatView('view1', 'v1', 'col = 0 AND col1 = ''comp''')) p");
rs.next();
assertEquals(0, rs.getInt(1));
rs = s.executeQuery("select * from (call sysadmin.updateMatView('view1', 'v1', 'col = 1 AND col1 = ''comp''')) p");
rs.next();
assertEquals(1, rs.getInt(1));
rs = s.executeQuery("select * from v1");
rs.next();
assertNotEquals(previous, rs.getDouble(3));
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testInternalWriteThroughMativew.
@Test
public void testInternalWriteThroughMativew() throws Exception {
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("m");
mmd2.setModelType(Type.PHYSICAL);
mmd2.addSourceMapping("x", "x", null);
mmd2.addSourceMetadata("DDL", "CREATE foreign TABLE t (col string, colx string) options (updatable true); " + "CREATE VIEW v1 (col1 string, col2 string, primary key (col1)) " + "OPTIONS (updatable true, MATERIALIZED true, \"teiid_rel:MATVIEW_WRITE_THROUGH\" true) AS /*+ cache(updatable) */ select col, colx from t;");
HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hcef.addData("SELECT t.col, t.colx FROM t", Arrays.asList(Arrays.asList("a", "ax")));
hcef.addData("SELECT t.col, t.colx FROM t WHERE t.col = 'b'", Arrays.asList(Arrays.asList("b", "d")));
hcef.addUpdate("INSERT INTO t (col, colx) VALUES ('b', 'd')", new int[] { 1 });
server.addTranslator("x", hcef);
server.deployVDB("comp", mmd2);
Connection c = server.getDriver().connect("jdbc:teiid:comp", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from v1");
rs.next();
assertEquals("a", rs.getString(1));
s.execute("insert into v1 (col1, col2) values ('b', 'd')");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(2, rs.getInt(1));
hcef.addUpdate("DELETE FROM t WHERE t.col = 'b'", new int[] { 1 });
hcef.addData("SELECT t.col, t.colx FROM t WHERE t.col = 'b'", new ArrayList<List<?>>());
s.execute("delete from v1 where v1.col1 = 'b'");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(1, rs.getInt(1));
hcef.addUpdate("UPDATE t SET colx = 'bx' WHERE t.colx = 'ax'", new int[] { 1 });
hcef.addData("SELECT t.col, t.colx FROM t WHERE t.col = 'a'", Arrays.asList(Arrays.asList("a", "ax")));
s.execute("update v1 set col2 = 'bx' where col2 = 'ax'");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select col2, col1 from v1");
rs.next();
assertEquals("ax", rs.getString(1));
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestMatViews method testupdateMatViewInternalNoPK.
@Test(expected = TeiidSQLException.class)
public void testupdateMatViewInternalNoPK() throws Exception {
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("view1");
mmd2.setModelType(Type.VIRTUAL);
mmd2.addSourceMetadata("DDL", "CREATE VIEW v1 ( col integer, col1 string, col2 double ) OPTIONS (MATERIALIZED true) AS /*+ cache(updatable) */ select 1, current_database(), rand()");
server.deployVDB("comp", mmd2);
Connection c = server.getDriver().connect("jdbc:teiid:comp", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from v1");
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("comp", rs.getString(2));
s.execute("call sysadmin.updateMatView('view1', 'v1', 'col = 1')");
}
Aggregations