Search in sources :

Example 41 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testLateralTupleSourceReuse.

@Test
public void testLateralTupleSourceReuse() throws Exception {
    es.start(new EmbeddedConfiguration());
    int rows = 20;
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("y");
    mmd.addSourceMetadata("ddl", "CREATE VIRTUAL PROCEDURE pr0(arg1 string) returns (res1 string) AS\n" + "    BEGIN\n" + "        SELECT '2017-01-01';\n" + "    END;" + "create foreign table test_t1(col_t1 varchar) options (cardinality 20); create foreign table test_t2(col_t2 integer) options (cardinality 20);");
    mmd.addSourceMapping("y", "y", null);
    HardCodedExecutionFactory hcef = new HardCodedExecutionFactory();
    es.addTranslator("y", hcef);
    es.deployVDB("x", mmd);
    String sql = "SELECT d.col_t2 FROM \"test_t1\", table(CALL pr0(\"arg1\" => col_t1)) x\n" + "     join table(select * from \"test_t2\") d \n" + " on true " + "UNION all\n" + "SELECT d.col_t2 FROM \"test_t1\", table(CALL pr0(\"arg1\" => col_t1)) x\n" + "    join table(select * from \"test_t2\") d \n" + " on true " + "        limit 100";
    List<?>[] vals = new List<?>[rows];
    Arrays.fill(vals, Arrays.asList("1"));
    List<?>[] vals1 = new List<?>[rows];
    Arrays.fill(vals1, Arrays.asList(1));
    hcef.addData("SELECT test_t1.col_t1 FROM test_t1", Arrays.asList(vals));
    hcef.addData("SELECT test_t2.col_t2 FROM test_t2", Arrays.asList(vals1));
    Connection c = es.getDriver().connect("jdbc:teiid:x;", null);
    Statement s = c.createStatement();
    s.executeQuery(sql);
    ResultSet rs = s.getResultSet();
    int count = 0;
    while (rs.next()) {
        count++;
    }
    rs.close();
    assertEquals(100, count);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 42 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testMultiSourceMetadataMissingSource.

/**
 * Check that we'll consult each source
 * @throws Exception
 */
@Test
public void testMultiSourceMetadataMissingSource() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("t", new ExecutionFactory<Object, Object>() {

        @Override
        public Object getConnection(Object factory) throws TranslatorException {
            return factory;
        }

        @Override
        public void closeConnection(Object connection, Object factory) {
        }

        @Override
        public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
            assertNotNull(conn);
            Table t = metadataFactory.addTable("x");
            metadataFactory.addColumn("a", "string", t);
        }
    });
    es.addConnectionFactory("b", new Object());
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("b");
    mmd1.setSupportsMultiSourceBindings(true);
    // a is missing
    mmd1.addSourceMapping("x", "t", "a");
    mmd1.addSourceMapping("y", "t", "b");
    es.deployVDB("vdb", mmd1);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslatorException(org.teiid.translator.TranslatorException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 43 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testInvalidName.

@Test(expected = VirtualDatabaseException.class)
public void testInvalidName() throws Exception {
    es.start(new EmbeddedConfiguration());
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("virt.1");
    mmd1.setModelType(Type.VIRTUAL);
    mmd1.setSchemaSourceType("ddl");
    mmd1.setSchemaText("create view \"my-view\" as select 1");
    es.deployVDB("x", mmd1);
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 44 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testDeploy.

@Test
public void testDeploy() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("y", new FakeTranslator(false));
    final AtomicInteger counter = new AtomicInteger();
    ConnectionFactoryProvider<AtomicInteger> cfp = new EmbeddedServer.SimpleConnectionFactoryProvider<AtomicInteger>(counter);
    es.addConnectionFactoryProvider("z", cfp);
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("my-schema");
    mmd.addSourceMapping("x", "y", "z");
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("virt");
    mmd1.setModelType(Type.VIRTUAL);
    mmd1.setSchemaSourceType("ddl");
    mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");
    es.deployVDB("test", mmd, mmd1);
    TeiidDriver td = es.getDriver();
    Connection c = td.connect("jdbc:teiid:test", null);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select * from \"my-view\"");
    assertFalse(rs.next());
    assertEquals("my-column", rs.getMetaData().getColumnLabel(1));
    s.execute("update \"my-view\" set \"my-column\" = 'a'");
    assertEquals(2, s.getUpdateCount());
    es.deployVDB("empty");
    c = es.getDriver().connect("jdbc:teiid:empty", null);
    s = c.createStatement();
    s.execute("select * from sys.tables");
    assertNotNull(es.getSchemaDdl("empty", "SYS"));
    assertNull(es.getSchemaDdl("empty", "xxx"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TeiidDriver(org.teiid.jdbc.TeiidDriver) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 45 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestEmbeddedServer method testTranslatorCreation.

@Test
public void testTranslatorCreation() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator(DummyExecutionFactory.class);
    Map<String, String> props = new HashMap<String, String>();
    props.put("supportsOrderBy", "true");
    es.addTranslator("dummy-override", "dummy", props);
    ModelMetaData mmd = new ModelMetaData();
    mmd.setName("test-one");
    mmd.addSourceMapping("one", "dummy", null);
    ModelMetaData mmd2 = new ModelMetaData();
    mmd2.setName("test-two");
    mmd2.addSourceMapping("two", "dummy", null);
    ModelMetaData mmd3 = new ModelMetaData();
    mmd3.setName("test-three");
    mmd3.addSourceMapping("three", "dummy-override", null);
    es.deployVDB("test", mmd, mmd2, mmd3);
    TeiidDriver td = es.getDriver();
    Connection c = td.connect("jdbc:teiid:test", null);
    Statement s = c.createStatement();
    s.execute("select count(distinct name) from sys.tables where name like 'test%'");
    s.getResultSet().next();
    assertEquals(3, s.getResultSet().getInt(1));
    s.execute("select count(distinct name) from sys.columns where tablename like 'test%'");
    s.getResultSet().next();
    assertEquals(2, s.getResultSet().getInt(1));
}
Also used : HashMap(java.util.HashMap) TeiidDriver(org.teiid.jdbc.TeiidDriver) 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