Search in sources :

Example 1 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestNativeCassandra method testDirect.

@Test
public void testDirect() throws TranslatorException {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    cef.setSupportsDirectQueryProcedure(true);
    String input = "call native('select $1', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(rsf.getUninterruptibly()).toReturn(rs);
    Row row = Mockito.mock(Row.class);
    ColumnDefinitions cd = Mockito.mock(ColumnDefinitions.class);
    Mockito.stub(row.getColumnDefinitions()).toReturn(cd);
    Mockito.stub(rs.one()).toReturn(row).toReturn(null);
    Mockito.stub(connection.executeQuery("select 'a'")).toReturn(rsf);
    ResultSetExecution execution = (ResultSetExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : ColumnDefinitions(com.datastax.driver.core.ColumnDefinitions) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 2 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestUpdates method testBulkUpdate.

@Test
public void testBulkUpdate() throws Exception {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    String input = "insert into pm1.g1 (e1) values ('a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    Insert insert = (Insert) command;
    Parameter p = new Parameter();
    p.setType(String.class);
    p.setValueIndex(0);
    ((ExpressionValueSource) insert.getValueSource()).getValues().set(0, p);
    insert.setParameterValues(Arrays.asList(Arrays.asList("a"), Arrays.asList("b")).iterator());
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    Mockito.stub(connection.executeBatch(Mockito.eq("INSERT INTO g1 (e1) VALUES (?)"), (List<Object[]>) Mockito.anyObject())).toReturn(rsf);
    UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Parameter(org.teiid.language.Parameter) UpdateExecution(org.teiid.translator.UpdateExecution) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 3 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata 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 4 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata 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 5 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestODataIntegration method testCheckGeneratedColumns.

@Test
public void testCheckGeneratedColumns() throws Exception {
    HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {

        @Override
        public UpdateExecution createUpdateExecution(org.teiid.language.Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(new String[] { "a" }, new Class[] { String.class });
            keys.addKey(Arrays.asList("ax"));
            return super.createUpdateExecution(command, executionContext, metadata, connection);
        }

        @Override
        public boolean supportsCompareCriteriaEquals() {
            return true;
        }
    };
    hc.addUpdate("INSERT INTO x (b, c) VALUES ('b', 5)", new int[] { 1 });
    // this gets called right after insert.
    hc.addData("SELECT x.a, x.b, x.c FROM x WHERE x.a = 'ax'", Arrays.asList(Arrays.asList("a", "b", 2)));
    teiid.addTranslator("x", hc);
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("m");
        mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, " + "primary key (a)) options (updatable true);");
        mmd.addSourceMapping("x", "x", null);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider("{\"b\":\"b\", \"c\":5}"), "application/json").send();
        assertEquals(201, response.getStatus());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.query.sql.lang.Command) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) GeneratedKeys(org.teiid.GeneratedKeys) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)46 ExecutionContext (org.teiid.translator.ExecutionContext)40 Test (org.junit.Test)38 Command (org.teiid.language.Command)33 TranslationUtility (org.teiid.cdk.api.TranslationUtility)26 ResultSetExecution (org.teiid.translator.ResultSetExecution)14 QueryExpression (org.teiid.language.QueryExpression)11 TranslatorException (org.teiid.translator.TranslatorException)10 LdapContext (javax.naming.ldap.LdapContext)9 List (java.util.List)8 ExecutionFactory (org.teiid.translator.ExecutionFactory)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)7 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)7 ArrayList (java.util.ArrayList)6 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 SObject (com.sforce.soap.partner.sobject.SObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 EntityManager (javax.persistence.EntityManager)4 UpdateExecution (org.teiid.translator.UpdateExecution)4