Search in sources :

Example 1 with ExecutionFactory

use of org.teiid.translator.ExecutionFactory in project teiid by teiid.

the class TestConnectorWorkItem method testConversionError.

@Test
public void testConversionError() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<String> list1 = new ArrayList<String>();
            list1.add("1");
            List<String> list2 = new ArrayList<String>();
            list2.add("a");
            final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (iter.hasNext()) {
                        return iter.next();
                    }
                    return null;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    ef.setCopyLobs(true);
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] results = message.getResults();
    assertEquals(1, results.length);
    List<?> tuple = results[0];
    assertEquals(1, tuple.get(0));
    assertEquals(-1, message.getFinalRow());
    try {
        cwi.more();
        fail();
    } catch (TranslatorException e) {
    // should throw the conversion error
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) List(java.util.List) ArrayList(java.util.ArrayList) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 2 with ExecutionFactory

use of org.teiid.translator.ExecutionFactory in project teiid by teiid.

the class TestConnectorWorkItem method testUnmodifibleList.

@Test
public void testUnmodifibleList() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<String> list1 = Collections.singletonList("1");
            final Iterator<List<String>> iter = Arrays.asList(list1).iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (iter.hasNext()) {
                        return iter.next();
                    }
                    return null;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] results = message.getResults();
    assertEquals(1, results.length);
    List<?> tuple = results[0];
    assertEquals(1, tuple.get(0));
    assertEquals(1, message.getFinalRow());
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) List(java.util.List) ArrayList(java.util.ArrayList) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) QueryExpression(org.teiid.language.QueryExpression) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 3 with ExecutionFactory

use of org.teiid.translator.ExecutionFactory in project teiid by teiid.

the class TestDynamicImportedMetaData method testMultipleFK.

@Test
public void testMultipleFK() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer, z integer, primary key (y, z));" + "create foreign table z (y integer, z integer, y1 integer, z1 integer, foreign key (y, z) references x (y, z), foreign key (y1, z1) references x (y, z))");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:vdb");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.importKeys", "true");
    MetadataFactory mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
    List<ForeignKey> fks = t.getForeignKeys();
    assertEquals(2, fks.size());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 4 with ExecutionFactory

use of org.teiid.translator.ExecutionFactory in project teiid by teiid.

the class TestDynamicImportedMetaData method testMultiSource.

@Test
public void testMultiSource() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    TeiidExecutionFactory tef = new TeiidExecutionFactory() {

        @Override
        public void closeConnection(Connection connection, DataSource factory) {
        }
    };
    tef.setSupportsDirectQueryProcedure(true);
    tef.start();
    server.addTranslator("teiid", tef);
    DataSource ds = Mockito.mock(DataSource.class);
    Mockito.stub(ds.getConnection()).toReturn(server.getDriver().connect("jdbc:teiid:vdb", null));
    server.addConnectionFactory("teiid1", ds);
    server.addConnectionFactory("teiid2", ds);
    server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("multi.xml")));
    Connection c = server.createConnection("jdbc:teiid:multi", null);
    Statement s = c.createStatement();
    s.execute("call native('select ?', 'b')");
    ResultSet rs = s.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.next());
    assertFalse(rs.next());
    s.execute("call native(request=>'select ?', variable=>('b',), target=>'teiid1')");
    rs = s.getResultSet();
    assertTrue(rs.next());
    Object[] result = (Object[]) rs.getArray(1).getArray();
    assertArrayEquals(new Object[] { "b" }, result);
    assertFalse(rs.next());
}
Also used : TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) FileInputStream(java.io.FileInputStream) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 5 with ExecutionFactory

use of org.teiid.translator.ExecutionFactory in project teiid by teiid.

the class TestEmbeddedServer method testImportExcept.

@Ignore("limit to/exclude not yet implemented")
@Test
public void testImportExcept() throws Exception {
    es.start(new EmbeddedConfiguration());
    es.addMetadataRepository("x", new MetadataRepository() {

        @Override
        public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
            assertEquals("helloworld1,other", factory.getModelProperties().get("importer.excludeTables"));
            Table t = factory.addTable("helloworld");
            t.setVirtual(true);
            factory.addColumn("col", "string", t);
            t.setSelectTransformation("select 'HELLO WORLD'");
        }
    });
    String externalDDL = "CREATE DATABASE test VERSION '1';" + "USE DATABASE test VERSION '1';" + "CREATE VIRTUAL SCHEMA test2;" + "IMPORT FOREIGN SCHEMA public except (helloworld1, other) FROM REPOSITORY x INTO test2;";
    es.deployVDB(new ByteArrayInputStream(externalDDL.getBytes(Charset.forName("UTF-8"))), true);
    ResultSet rs = es.getDriver().connect("jdbc:teiid:test", null).createStatement().executeQuery("select * from helloworld");
    rs.next();
    assertEquals("HELLO WORLD", rs.getString(1));
}
Also used : MetadataRepository(org.teiid.metadata.MetadataRepository) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecutionFactory(org.teiid.translator.ExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ExecutionFactory (org.teiid.translator.ExecutionFactory)29 Test (org.junit.Test)18 TranslatorException (org.teiid.translator.TranslatorException)11 ExecutionContext (org.teiid.translator.ExecutionContext)9 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)8 ResultSetExecution (org.teiid.translator.ResultSetExecution)8 List (java.util.List)7 QueryExpression (org.teiid.language.QueryExpression)7 ArrayList (java.util.ArrayList)6 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)6 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)6 MetadataFactory (org.teiid.metadata.MetadataFactory)6 Connection (java.sql.Connection)5 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)5 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)5 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OracleExecutionFactory (org.teiid.translator.jdbc.oracle.OracleExecutionFactory)4 TeiidExecutionFactory (org.teiid.translator.jdbc.teiid.TeiidExecutionFactory)4 FileInputStream (java.io.FileInputStream)3