Search in sources :

Example 31 with RuntimeMetadata

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

the class TestNativeCassandra method testNativeQuery.

@Test
public void testNativeQuery() throws Exception {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    cef.setSupportsDirectQueryProcedure(true);
    String input = "call proc('a', 1)";
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign procedure proc (in x string, in y integer) options (\"teiid_rel:native-query\" 'delete from $1 where $2')", "x", "y");
    TranslationUtility util = new TranslationUtility(metadata);
    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(connection.executeQuery("delete from 'a' where 1")).toReturn(rsf);
    Execution execution = cef.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).executeQuery("delete from 'a' where 1");
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Execution(org.teiid.translator.Execution) ResultSetExecution(org.teiid.translator.ResultSetExecution) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 32 with RuntimeMetadata

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

the class TestUpdates method testBatchedUpdate.

@Test
public void testBatchedUpdate() throws TranslatorException {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    String input = "insert into pm1.g1 (e1) values ('a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    Command command1 = util.parseCommand("update pm1.g1 set e1 = 'b'");
    command = new BatchedUpdates(Arrays.asList(command, command1));
    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(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"))).toReturn(rsf);
    UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
    Mockito.verify(connection).executeBatch(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) BatchedUpdates(org.teiid.language.BatchedUpdates) Test(org.junit.Test)

Example 33 with RuntimeMetadata

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

the class TestSQLtoSpreadsheetQuery method testInsertExecution.

@Test
public void testInsertExecution() throws Exception {
    String sql = "insert into PeopleList(A,B,C) values ('String,String', 'val', 15.5)";
    Insert insert = (Insert) getCommand(sql);
    GoogleSpreadsheetConnection gsc = Mockito.mock(GoogleSpreadsheetConnection.class);
    Mockito.stub(gsc.getSpreadsheetInfo()).toReturn(people);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    SpreadsheetUpdateExecution sue = new SpreadsheetUpdateExecution(insert, gsc, ec, rm);
    sue.execute();
    LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
    vals.put("A", "String,String");
    vals.put("B", "val");
    vals.put("C", 15.5);
    Mockito.verify(gsc).executeRowInsert("PeopleList", vals);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 34 with RuntimeMetadata

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

the class TestTeiidTableMarsheller method helpExecute.

private IckleConversionVisitor helpExecute(String query) throws Exception {
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
    // System.out.println(DDLStringVisitor.getDDLString(mf.getSchema(), null, null));
    InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
    TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
    TranslationUtility utility = new TranslationUtility(metadata);
    Select cmd = (Select) utility.parseCommand(query);
    RuntimeMetadata runtimeMetadata = new RuntimeMetadataImpl(metadata);
    IckleConversionVisitor visitor = new IckleConversionVisitor(runtimeMetadata, false);
    visitor.visitNode(cmd);
    visitor.getQuery();
    return visitor;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Select(org.teiid.language.Select) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata)

Example 35 with RuntimeMetadata

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

the class ConnectorHost method executeBatchedUpdates.

public int[] executeBatchedUpdates(String[] updates) throws TranslatorException {
    RuntimeMetadata runtimeMetadata = getRuntimeMetadata();
    Command[] commands = new Command[updates.length];
    for (int i = 0; i < updates.length; i++) {
        commands[i] = getCommand(updates[i]);
    }
    return executeBatchedUpdates(commands, runtimeMetadata);
}
Also used : Command(org.teiid.language.Command) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata)

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