Search in sources :

Example 71 with ModelMetaData

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);
}
Also used : VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 72 with ModelMetaData

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");
    }
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) Connection(java.sql.Connection) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 73 with ModelMetaData

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));
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 74 with ModelMetaData

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));
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ArrayList(java.util.ArrayList) List(java.util.List) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 75 with ModelMetaData

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')");
}
Also used : Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)191 Test (org.junit.Test)131 Properties (java.util.Properties)50 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)45 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)43 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)36 Connection (java.sql.Connection)23 MetadataFactory (org.teiid.metadata.MetadataFactory)21 Statement (java.sql.Statement)19 ResultSet (java.sql.ResultSet)18 CallableStatement (java.sql.CallableStatement)16 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)15 ArrayList (java.util.ArrayList)13 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)11 Table (org.teiid.metadata.Table)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 List (java.util.List)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)9